Home > Web Front-end > JS Tutorial > jQuery Gets Objects Basic Selection and Level_jquery

jQuery Gets Objects Basic Selection and Level_jquery

WBOY
Release: 2016-05-16 18:26:01
Original
1310 people have browsed it

Select based on id (only one object can be selected by id), such as: $("#div2")

AAA

BBB

CCC


Select according to tags, such as: $("span")
AAA

BBB

CCC

Class name based on style Select, such as: $(".class1")
AAA

BBB

CCC


Selecting all objects is: $("*")

Can be mixed, such as: $("#btn2, .class1, span")

Copy code The code is as follows:







span1









< /div>
span2


<script> <br>//Modify the color style of the selected object to red <br>$("#btn2, .class1, span").css("color", "red"); <br></script>


jQuery Gets Objects Basic Selection and Level_jquery
Can be selected hierarchically, such as: $(".class1 div label")

111

222

< ;label>333

444

555

For example: $(".class1 span") or $(".class1").find("span")

< div id="id1">111

222


444

555


Select only from sub-layers, such as: $(".class1 > span"); If there is no middle >, all eligible descendant objects below it will be selected

111

222

444
555


followed by, such as: $("div span"); This will select everything immediately following the div span

111

222


444< ;br/>
555


At the same level (behind), such as: $("#id2 ~ *"); This is to select all (*) objects at the same level behind #id2

111

< div id="id2">222


444

555


Mixed use, such as: $( "#id3 label, #id3 ~ span")

111

222


< ;span>444

555


Select other elements at the same level, such as: $ ("#id2").siblings()

111

222


< span>444

555


Select other spans at the same level, such as: $( "#id2").siblings("span")

111

222


444

555



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