jquery-Get child element Children,find

Source: Internet
Author: User

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 ()

Here is a brief introduction to the similarities and differences between the following 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 child element of a subordinate 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), which 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 ').

Cases:

<ulclass= "Level-1">  <Liclass= "Item-i">I</Li>  <Liclass= "Item-ii">II<ulclass= "Level-2">      <Liclass= "Item-a">A</Li>      <Liclass= "Item-b">B<ulclass= "Level-3">          <Liclass= "Item-1">1</Li>          <Liclass= "Item-2">2</Li>          <Liclass= "Item-3">3</Li>        </ul>      </Li>      <Liclass= "Item-c">C</Li>    </ul>  </Li>  <Liclass= "ITEM-III">Iii</Li></ul>

Use:

The effect is:

Use $ (' Ul.level-2 '). Find (' Li '). CSS (' border ', ' 1px solid green '); The effect is:

jquery-Get child element Children,find

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.