Jquery selector to exclude a DOM element (example) _ jquery

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.