Home  >  Article  >  Web Front-end  >  Detailed explanation of content filtering selector of jquery selector_jquery

Detailed explanation of content filtering selector of jquery selector_jquery

WBOY
WBOYOriginal
2016-05-16 17:02:201244browse

First write the HTML structure of the DOM element:

Copy the code The code is as follows:



Copy code The code is as follows:

John Resign

George Martin

Malcom John Sinclair

J.Ohn



Has p



1. :contains(text)
Select elements with text content "text"
Copy code The code is as follows:

$("div:contains('John')").addClass("highlight"); //Find all div elements containing "John"


2. :empty
Select an empty element that does not contain any child elements or text
Use the chrome browser to inspect the element and you will find that the class style of the div empty has been changed
Copy code The code is as follows:

$("div:empty").addClass("highlight ");


3. :has(selector)
Select the element containing the element matched by the selector
Copy code The code is as follows:

$("div:has(p)").addClass("highlight") ; //Find all div elements containing p



4. :parent
Select element tags containing child elements or text
Copy code The code is as follows:

$("div:parent").addClass(" highlight"); //Find all div elements containing child elements or text

Statement:
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