One: Common selector: $ ("#id")//by ID//returns a single element$("Div")//by label$(". CLS")//class Selector$("Div.cls")//tag plus class selector$("*")//Select all the elements$( This)//own$("Div,p,a")//get a collection of all tags$("Div P")//all the <p> under the Div, no matter how many layers [descendants]$("div>p")//get the most direct p [son]$("div+p")//the first element below the sibling node [brother]//equivalent to. Next ();$("div~p")//all the following sibling nodes of the layer//equivalent to. nextall ();II: Commonly used filters:: EQ (): Index//1th element $ (' p:eq (0) '): Not (): unsatisfied"Selector Selector"elements: First: One: Last: Final: animated: All elements that are animating: contains (text): Select the element that contains text//no quotes like effect: Empty: Select a blank element that does not contain elements or text//<div></div> test pass, line break should also count characters, cannot be selected (browser problem, CSS problem): Has (selector): Select the element that contains the matching element:p arent: Select the element that contains the child element or text: Hidden: Select all invisible elements $ (": Hidden")//elements that include Display:none: Visible: Select all visible Elements $ ("div:visible") :checked: selected: selecetd: Selected [ID]: Select the element that owns the id attribute//("Div[style]"). Hide (2000); Test failed.//("Div[id]"). Hide (2000); test pass[id=text]: Select an element with ID of text [ID!=text]: Select an element with an ID other than text [ID^=T]: Select an element whose ID starts with T [id$=T]: Select an element with an ID that ends with T [ID*=text]: Select the element whose ID contains text three: Select elements: About DOM objects and jquery objects: the latter is the encapsulation of the former $ ("#sel"): The jquery object with the ID sel, actually returns the array. $("#sel")[0]: Is the DOM object encapsulated within a jquery object with ID sel, which is the element itself. $(". Class"): Is a collection of jquery objects of class class four: Gets the selected value of select: $ ("#sel"). Val (): Gets the selected value of the Select. Five: Iterate through the same checkbox with the same class name to get multiple checkbox check values:varCK = $ (". Check"); for(varI=0; I <ck.length; i++) { if(Ck.eq (i) [0].checked==true{alert (Ck.eq (i). Val ()); } VI: Traverse the same class name RadioButton, get multiple RadioButton selected values:varCK = $ (". Radio"); for(varI=0; I <ck.length; i++) { if(Ck.eq (i) [0].checked==true{alert (Ck.eq (i). Val ()); } }
This article is reproduced from teacher Li
20151227:jquery element Selection and value < turn >