This article mainly introduces the usage of the jQuery content filter selector. examples show how to use the content filter selector, such as contains (), has (), empty (), and parent, for more information about jQuery content filtering selector, see the following example. Share it with you for your reference. The specific analysis is as follows:
In an HTML document, the content of an element can be text or child elements. if you use a selector or content filter selector together, you can further filter the elements that have been queried to generate a given
Elements of text or child elements
1.: contains () selector
Used to select all elements that contain the given text. format:
The code is as follows:
$ ("Selector1: contains (text )")
For example:
The code is as follows:
$ ("P: contains ('text')" ).css ("background", "# FCF ");
2.: has () selector
Used to filter the elements that are contained in the subelement. format:
The code is as follows:
$ ("Selector1: has (selector2 )")
Selector1 and selector2 are any valid elements.
For example:
The code is as follows:
$ ("Li: has (p)" ).css ("background", "red ");
3.: empty () selector
Format:
The code is as follows:
$ ("Selector: empty ")
Used to select all elements that do not contain child elements or text. all null elements in selector that do not contain child elements or text will be included in the query results.
For example:
The code is as follows:
$ ("Td: empty" ).css ("background", "# FCF ");
4.: parent selector
Format:
The code is as follows:
$ ("Selector: parent ")
Used to select an element that contains child elements or text, which is opposite to the empty selector.
For example:
The code is as follows:
$ ("Td: parent" ).css ("background", "# FCF ");
I hope this article will help you with jQuery programming.