This article mainly introduces how to exclude a DOM element by using the jquery selector, that is, to filter unnecessary elements in the selected elements and implement them using the jquerynot selector, for more information about how to select a DOM, see jquery selector. There are many methods to select a DOM. How to exclude a certain element set? The following are examples:
1. Select All img elements to exclude the number of elements in class = phpernote:
The Code is as follows:
$ ('Img: not (. phpernote) '). length (); // or $ ('img'). not ('. phpernote'). length ();
2. Obtain the number of li elements without class = com under id = phpernote
The Code is as follows:
$ ('# Phpernote li: not (. com )'). size (); // or $ ('# phpernote li '). not ('. com '). length ();
3. Set the background of the li element of all odd rows under id = phpernote
The Code is as follows:
$ ('# Phpernote li'). not (': even'background .css ('background-color', 'red ');
Example: exclude the specified element from jQuery and select all the remaining elements.
Scenario: a page uses the js delayed loading technology to process all images to improve the user experience. However, if you do not want to load a few images in a delayed manner, you need to pick them out separately.
After studying jQuery's API documentation, I got rid of it. jQuery is really convenient. I will paste it here for backup:
The Code is as follows:
Yang Guo under the bodhi tree