Filter Selector
4. Attribute Filter
Find all DIV elements with ID attributes
$ (document). Ready (function () {
$ ("Div[id]"). CSS ("Color", "red");
});
<body>
<div>test1</div>
<div id= "D" >TEST2</DIV>
</body>
Find all Name qin input and select
$ (document). Ready (function () {
$ ("Input[name= ' Qin ')"). attr ("Checked", "true");
});
</script>
finds all input with name other than Qin and selects
$ (document). Ready (function () {
$ ("input[name!= ' Qin ']"). attr ("Checked", "true");
});
Look for all input
$ (document) whose name begins with Qin. Ready (function () {
$ ("input[name^= ' Qin ')"). attr ("Checked", "true");
});
Find all input with name ending in lol and select
$ (document). Ready (function () {
$ ("input[name$= ' lol ']"). attr ("Checked", "true") ;
});
Find all the name of input with O and select
$ (document). Ready (function () {
$ ("input[name*= ' O ']"). attr ("Checked", "true");
}); The
finds all the input that contains the id attribute and the end of name is E and selects
$ (document). Ready (function () {
$ ("input[id][name$= ' e ']"). attr (" Checked "," true ");
});
<body>
<input type= "checkbox" Name= "Qin" value= "Hot Fuzz"/>1
<input type= "checkbox" Name= "Yilol" value= "Cold Fusion"/>2
<input type= "checkbox" Name= "Love" value= "Evil plans"/>3
</body>
5. Child element Filter Selector
Second LI matching UL (index starting from 1)
$ (document). Ready (function () {
$ ("UL Li:nth-child (2)"). CSS ("Color", "red");
});
Matches only ul 1th element
$ (document). Ready (function () {
$ ("ul Li:first-child"). CSS ("Color", "red");
});
Match ul last Li
$ (document). Ready (function () {
$ ("ul Li:last-child"). CSS ("Color", "red");
});
Matching UL is the only Li
$ (document). Ready (function () {
$ ("ul Li:only-child"). CSS ("Color", "red");
});
<body>
<div>test1</div>
<div id= "D" >test2</div>
<input type= "checkbox" Name= "Qin" value= "Hot Fuzz"/>1
<input type= "checkbox" Name= "Yilol" value= "Cold Fusion"/>2
<input type= "checkbox" Name= "Love" value= "Evil plans" id= "test"/>3
<ul>
<li>qin</li>
<li>yi</li>
<li>test</li>
</ul>
<ul>
<li>only</li>
</ul>
</body>
6. Form object Property Filter Selector
Match all the available input elements
$ (document). Ready (function () {
$ ("input:enabled"). attr ("Checked", "true");
});
Match all input elements that are not available
$ (document). Ready (function () {
$ ("input:disabled"). attr ("Checked", "true");
});
Matches all selected input elements (checkboxes, radio boxes, etc., excluding option in select)
$ (document). Ready (function () {
$ ("input:checked"). attr ("Checked", "true");
});
Match all selected option elements (drop-down list)
$ (document). Ready (function () {
$ ("Select Option:selected"). CSS ("Background", "#bfa");
});
<body>
<input type= "checkbox" Name= "Qin" value= "Hot Fuzz"/>1
<input type= "checkbox" Name= "Yilol" value= "Cold Fusion"/>2
<input type= "checkbox" Name= "Love" value= "Evil plans" id= "test"/>3
<input type= "checkbox" name= "email" disabled= "disabled"/>disabled
<select>
<option value= "1" >qin</option>
<option value= "2" selected= "selected" >yi</option>
<option>test</option>
</select>
</body>
7.7. Form Selector
Match all input types:
$ (document). Ready (function () {
$ (": Input"). CSS ("Background", "#bfa");
});
Match all text boxes:
$ (document). Ready (function () {
$ (": Text"). CSS ("Background", "#bfa");
});
Match all Password boxes:
$ (document). Ready (function () {
$ (":p assword"). CSS ("Background", "#bfa");
});
Matches all radio buttons:
$ (document). Ready (function () {
$ (": Radio"). CSS ("Background", "#bfa");
});
Match all check boxes:
$ (document). Ready (function () {
$ (": CheckBox"). CSS ("Background", "#bfa");
});
Match all Submit buttons:
$ (document). Ready (function () {
$ (": Submit"). CSS ("Background", "#bfa");
});
<body>
<div>test1</div>
<div id= "D" >test2</div>
<input type= "button" value= "input button"/>
<input type= "checkbox"/>
<input type= "Password"/>
<input type= "Radio"/>
<input type= "Reset"/>
<input type= "Text"/>
<input type= "Submit"/>
</body>
jquery Selector (iii)