jquery selector Gets the parent element, sibling element, child element

Source: Internet
Author: User
First, get the parent element
1. Parent ([expr]): Gets all the parent elements of the specified element
Second, get the sibling elements:
1, next ([expr]): Gets the next sibling element of the specified element
2. Nextall ([expr]): Gets all sibling elements behind the specified element
<p>Hello</p>
<p>hello again</p>
<div><span>and again</span> </div>

var P_nex = $ ("P"). Nextall (). Andself ();
P_nex.addclass (' P_next_all ');
Select all the sibling tags that follow the p tag, and
4, prev (): Gets the previous sibling element of the specified element
5, Prevall (): Gets all sibling elements in front of the specified element, index from near [0]->[n]
Third, get child elements
1. Find child element mode 1:>
For example: var anods = $ ("ul > a"); Find all a labels under UL
2. Find child element Mode 2:children ()
3. Find child element Mode 3:find ()
Similarities and differences between children () and find ():
The 1> 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 sub-elements of the next level of the element, namely: immediate children.
The 3> Find method obtains all subordinate elements, namely: descendants of these elements in the DOM tree
The parameter selector of the 4> children method is optional (optionally) and is used to filter the 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 ').


Reprint Address: http://www.cnblogs.com/Tally/archive/2013/01/04/2844042.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.