Home > Web Front-end > JS Tutorial > How to exclude a certain DOM element using jquery selector (example demonstration)_jquery

How to exclude a certain DOM element using jquery selector (example demonstration)_jquery

WBOY
Release: 2016-05-16 16:51:14
Original
1362 people have browsed it

There are many jquery selectors, and there are many ways to select a certain DOM. How to exclude a certain set of selected elements? Here are some examples:

1. Select all img elements, excluding the number of elements with class=phpernote:

Copy the code The code is as follows:
$('img:not(.phpernote)').length();//or $('img').not('.phpernote').length();

2. Get the number of all li elements without class=com under id=phpernote
Copy the code The code is as follows:

$('#phpernote li:not(.com)').size();//or $('#phpernote li').not('.com').length();

3. Set the background of the li elements of all odd-numbered rows under id=phpernote
Copy the code The code is as follows:
$('#phpernote li').not(':even').css('background-color', 'red');

Attached example: exclude specified elements in jQuery and select all remaining elements

Scenario: A certain page uses js delayed loading technology to process all images to improve user experience, but there are several images that do not want delayed loading and require them to be singled out.
I studied jQuery’s API documentation and figured it out. jQuery is really convenient. Post it here for backup:

Copy the code The code is as follows:



Yang Guo under the Bodhi Tree




div 1

< div delay="false">div 2

div 3



above The code will exclude divs with the additional attribute "delay" and equal to "false", then select all the remaining divs and set them to red fonts.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template