Home  >  Article  >  Web Front-end  >  Summary of jQuery's powerful selectors_jquery

Summary of jQuery's powerful selectors_jquery

WBOY
WBOYOriginal
2016-05-16 18:38:091109browse
A basic selector
$("input"): Select all elements with input tags
$("#input1"): Select the element with the id of input1
$(" .acss"): Select all
codes that contain acss this css class style
Copy the code The code is as follows:


link

< input id="Text1" class="acss">

<script> <br>var oo = $("input"); //oo is The set of the above 3<br>var pp = $("#input1");//pp is the first one<br>var qq = $(".acss");//qq is the set of the first two<br></script>


You can use the above 3 combined queries
var ww = $("input.acss"); / /Select the input tag element with acss
var ee = $("input#Text1.acss");//Select the input tag element with acss ID of Text1
2. Sub-selection
The parent node and the direct child node are separated by (>), that is, the child selector method is implemented
Copy code The code is as follows:












< /a>


< ;/a>



< ;script>
var oo = $("p a "); //Selected all a below p
var pp = $("p>a"); //Selected 2 a elements, The ids are a1 and a2
var qq = $("p.acss a"); //The element with id a1 is selected


3. Feature selector
Select a[href^=http://]
Code
Copy code The code is as follows:








< script>
var oo = $("a[href^=http://]"); //Select a whose href starts with http://. a3 selects
var pp = $("input[name$=Input]"); //Select the input whose name ends with Input. Text3, Text4 selected
var qq = $("a[href*=com]"); //Select href to include a of com. a3, a4 are selected
var ww = $("input[id=Text3]"); //Select exactly equal to


In addition, jQuery also provides the has method, as in the above example,
div:has(input) means.Select all divs containing input
Note: div input selects all input elements in the div
4. Position selector
The position selector is mainly based on the position of the element. Select,
div a:first returns the first a in the div on the page
div a last returns the last a in the div on the page
div odd returns the div at the even position on the page
div even Return the idv of the odd position on the page
div first-child Returns the first child selection in the div
div last-child Returns the last child selection in the div
only-child element without sibling nodes
nth -child(n): nth child node
eq(n) nth matching element
gt(n) matching elements after n do not contain
lt(n) matching elements before n do not contain
5. jQuery custom selection
名称 说明 解释
:input 匹配所有 input, textarea, select 和 button 元素 查找所有的input元素: 
$(":input")
:text 匹配所有的文本框 查找所有文本框: 
$(":text")
:password 匹配所有密码框 查找所有密码框: 
$(":password")
:radio 匹配所有单选按钮 查找所有单选按钮
:checkbox 匹配所有复选框 查找所有复选框: 
$(":checkbox")
:submit 匹配所有提交按钮 查找所有提交按钮: 
$(":submit")
:image

匹配所有图像域

匹配所有图像域: 
$(":image")
:reset 匹配所有重置按钮 查找所有重置按钮: 
$(":reset")
:button 匹配所有按钮 查找所有按钮: 
$(":button")
:file 匹配所有文件域 查找所有文件域: 
$(":file")

名称 说明 解释
:enabled

匹配所有可用元素

Find all available input elements:
$("input:enabled")
:disabled Match all unavailable elements Find all disabled input elements:
$("input:disabled")
:checked Matches all selected selected elements (check boxes, radio buttons, etc., excluding options in select) Find all checked checkbox elements:
$("input:checked")
:selected Matches all selected option elements Find all selected option elements:
$("select option:selected")
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