JQ selector for yourself

1. Basic selector
$("#id") //ID selector
$("div") //Element selector
$(".classname") //Class selector
$(".classname,.classname1,# id1") //Combination selector
2. Hierarchical selector
$("#id>.classname ") //Child element selector
$("#id .classname ") //Descendent element selector
$("#id + .classname ") //The next element selector
$("#id ~ .classname ") //The sibling element selector
3. Filter selector (emphasis)
$("li:first") //The first li
$("li:last") //The last li
$("li:even") //Select li with even subscript
$("li:odd") //Select li with odd subscript
$(" li:eq(4)") //li with subscript equal to 4
$("li:gt(2)") //li with subscript greater than 2
$("li:lt(2)") //subscript li less than 2
$("li:not(#runoob)") // pick all li except id="runoob"
3.2 Content filtering selectors
$("div:contains('Runob')") // Elements containing Runob text
$("td:empty") // Empty elements that do not contain child elements or text
$("div:has(selector)") //The element that contains the selector
$("td:parent") //The element that contains the child element or text
3.3 Visibility filter selector
$("li:hidden" ) //Match all invisible elements, or elements whose type is hidden
$("li:visible") //Match all visible elements
3.4 Attribute filter selector
$("div[id]") //All elements with id attribute div element
$("div[id='123']") // div element with id attribute value of 123
$("div[id!='123']") // div element with id attribute value not equal to 123
$("div[id^='qq']") // div element whose id attribute value starts with qq
$("div[id$='zz']") // div element whose id attribute value ends with zz
$("div[id*='bb']") // div element whose id attribute value contains bb
$("input[id][name$='man']") //multi-attribute selection filter, and satisfy Conditional element
3.5 state filter selector for two attributes
$("input:enabled") // matches available inputs
$("input:disabled") // match unavailable input
$("input:checked") // match checked input
$("option:selected") // match checked option
4. Form selector
$(":input") //匹配所有 input, textarea, select 和 button 元素
$(":text") //所有的单行文本框,$(":text") 等价于$("[type=text]"),推荐使用$("input:text")效率更高,下同
$(":password") //所有密码框
$(":radio") //所有单选按钮
$(":checkbox") //所有复选框
$(":submit") //所有提交按钮
$(":reset") //所有重置按钮
$(":button") //所有button按钮
$(":file") //所有文件域

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325207748&siteId=291194637