JQuery content filtering selector tutorial _ jquery

Source: Internet
Author: User
This article mainly introduces jQuery's content filtering selector learning tutorial, detailed the usage of the four filters in jQuery, you can refer to the following content filter rules to filter sub-elements or text content.

$ ('P: contains ("xxx" example 'background .css ('background ',' # ccc '); // select the element whose text node contains the xxx text $ ('P: empty'background .css ('background', '# ccc'); // select an empty element $ ('ul: has(.red+'background .css ('background', '# ccc '); // select the child element $ (': parent'background .css ('background',' # ccc ') whose class is red. // select a non-empty Element

JQuery provides an has () method to improve the performance of the has filter:

Optional ('ul'background .has('.red'background .css ('background ',' # ccc '); // select the child element containing the element whose class is red.

JQuery provides a method similar to parent, but this method does not select an element containing child elements or text, but obtains the parent element of the current element, and returns a set of elements.

Certificate ('li').parent().css ('background ',' # ccc '); // select the parent element of the current element nickname ('li').parents().css ('background',' # ccc '); // select the parent element of the current element and the ancestor element parent ('li'}.parentsuntil('p'}.css ('background ',' # ccc '); // select the parent element p to stop when the current element is selected

The filtering rules of the jQuery content filter selector are mainly applied to the child elements contained in DOM elements or their text content. They mainly include the following four filtering methods:

For better learning, first write the HTML structure of several DOM elements:

John Resign

George Martin

Malcom John Sinclair

J.Ohn

Has p

I. Content Filtering selector --: contains (text)
Selector:

E: contains (text) // E refers to the text contained in the DOM element: contains (text). text indicates the string to be searched.
Description:

Select an element with the text content as "text"

Return Value:

Set Element

Instance:

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.