Home > Web Front-end > JS Tutorial > jQuery gets objects based on attributes, content matching, and form element matching_jquery

jQuery gets objects based on attributes, content matching, and form element matching_jquery

WBOY
Release: 2016-05-16 18:25:58
Original
1120 people have browsed it

The specified element contains the id attribute, such as: $("span[id]")

Copy code The code is as follows:

AAA



CCC

DDD< ;/span>

EEE

FFF

The specified element does not contain the id attribute, such as: $("span:not(span[id])") or $("span:not([id])")
Copy code The code is as follows:

AAA

BBB

CCC

DDD

EEE

FFF


contains the id attribute, such as: $(" body [id]")
Copy code The code is as follows:

AAA

BBB

CCC

DDD

EEE

FFF


matches the element value , such as: $("span[name='S2']")
Copy code The code is as follows:

AAA

BBB< ;/span>

CCC

DDD

EEE

FFF


Does not match the element value, such as: $("span[name!='S2']")
Copy code The code is as follows:

AAA

BBB

CCC

DDD

EEE

FFF


The element value starts with ?, such as: $("span[name^='S']")
Copy code The code is as follows:

AAA
BBB

CCC< ;/span>

DDD

EEE

FFF


The element value ends with ?, such as: $("html [name$= '1']")
Copy code The code is as follows:

AAA

BBB

CCC

DDD< /span>

EEE

FFF


The element value contains?, such as: $("body [name*='x']")
Copy code The code is as follows:

AAA

BBB

CCC

DDD

EEE

FFF


Multiple attribute conditions, such as (with id and name starting with "D"): $("body [id][name^= 'D']")
Copy code The code is as follows:

AAA

BBB

CCC

DDD

EEE

FFF


Find contains " AB" span: $("span:contains('AB')")
Copy code The code is as follows:

ABC

ABC



ABC

ABC




Find the div containing "AB" span: $("div span:contains('AB')")
Copy code The code is as follows:

ABC

ABC

< ;span>

ABC

ABC< ;/span>




Find contained span: $("span:has ('b')")
Copy code The code is as follows:

ABC< ;/span>

ABC



ABC

ABC



Find empty span: $("span:empty")
Copy code The code is as follows:

ABC

ABC



ABC

ABC


element) span: $("span:parent")


ABC


ABC

ABC




:hidden and :visible correspond to hidden and displayed elements respectively; below For example, make the displayed ones red and the hidden ones gray.






111

222

333

444


< ;/html>
<script> <br>$("div:visible").css("color", "red"); <br>$("div:hidden").css("display ", "").css("color", "silver"); <br></script>


Form matching:
:input matching:





:text Matches
:password matches
:radio matches
: checkbox matches
:submit matches
:reset matches
:image matches
:file matches
:button matches
:enabled Matches all available input elements
: disabled Matches all unavailable input elements
: checked Matches all selected checked check boxes and radio buttons
: selected Matches all selected option elements
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template