One, gets the parent element 1, parent ([expr]): Gets all the parent elements of the specified element href_firhref_sechref_thrHREF_FIV$ (document). Ready (function () {$ ("a"). Parent (). addclass (' A_par ');}); Firebug View jquery Parent effect Two, get sibling elements: 1, next ([expr]): Gets the next sibling element of the specified element (note the next sibling element OH)
- List Item 1
- List Item 2
- List Item 3
- List Item 4
- List Item 5
$ (' Li.third-item '). Next (). CSS (' background-color ', ' red '); The result of this example is that only the list item 4 background color changes to Red 2, nextall ([expr]): Gets all sibling elements behind the specified element Hellohello Againand Againvar P_nex = $ ("P"). Nextall ();p _nex.addclass (' P_next_all '); Firebug_jq_nextall take a look at the last one. Hello
Hello Again
and Againvar P_nex = $ ("P"). Nextall (). Andself ();p _nex.addclass (' P_next_all '); Watch the first one.
"tag Ah, this sentence means to select all the sibling tags after the P tag, as well as their own ... Firebug_jq_andself the following two do not cite specific examples, is actually the opposite of next () and Nextall () 4, prev (): Gets the previous sibling element of the specified element (is the last OH). 5, Prevall (): Gets all sibling elements in front of the specified element. Third, get child element 1, find child element way 1:> For example: var anods = $ ("ul > a"); Find all a label under UL equivalent to children (),> after no parameter equivalent to find the next level of all child elements, have parameters, filter 2, Find child element mode the 2:children () children () parameter is optional, equivalent to filtering in child elements, children () can only get the next level of child elements, sub-elements of the next level of child elements are not obtained; 3, find child elements way 3:find () find ( Selector) parameter must have a matching element found in all child elements of the current element and child elements of the child element here is a brief description of the similarities and differences between the following children () and find ():1> The children and find methods are used to obtain the sub-elements of element, neither of which will return text node, just like most jquery methods. The 2> children method obtains only the child element of a subordinate element, namely: immediate children. 3> Find method obtains all subordinate elements, namely: descendants of these elements in the DOM tree 4> children method parameter selector is optional (optionally), used to filter child elements , but the parameter selector method of the Find method is required. The 5> Find method can actually be implemented by using JQuery (selector, context). That is $ (' li.item-ii '). Find (' Li ') is equivalent to $ (' Li ', ' li.item-ii '). Example:
Use: $ (' Ul.level-2 '). Children (). CSS (' border ', ' 1px solid green '), using $ (' Ul.level-2 '). Find (' Li '). CSS (' border ', ' 1px Solid green ');
jquery selector Gets the parent element, sibling element, child element