JQuery traversal element descendant and compatriot implementation method, jquery descendant

Source: Internet
Author: User

JQuery traversal element descendant and compatriot implementation method, jquery descendant

1. Traverse future generations

Children ()

The children () method returns all direct child elements of the selected element.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Find ()

The find () method returns the child element of the selected element, all the way down until the last child.

Selecter must be added to find (). If selecter is not added, it cannot be displayed.

Therefore, a selector such as find ("*") find ("span") must be added ")

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

2. Traverse compatriots

Siblings ()

The siblings () method returns all the compatriot elements of the selected element.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Next ()

Next () The next compatriot element of the selected Element

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

NextAll ()

The nextAll () method returns all siblings of the selected element.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

NextUntil ()

The nextUntil () method returns all the following compatriot elements between two given parameters.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Prev ()

Prev ()
PrevAll ()
PrevUntil ()
Prev = previous

So the traversal is the first compatriot of the specified element. This effect is similar to next ().

3. Filter

First ()

The first () method returns the first element of the selected element.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Last ()

The last () method returns the last element of the selected element.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Eq ()

The eq () method returns the elements with the specified index number in the selected element.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Filter ()

The filter () method allows you to specify a standard. Elements that do not match this standard will be deleted from the set, and matched elements will be returned.

<script type="text/javascript">$(function(){$("#btn").click(function(){$("div p").filter("#p2").each(function(i, e) {    $("#info").html($("#info").html()+"("+$(this).attr("id")+")");   }); });});</script>

Not ()

The not () method returns all elements that do not match the standard.

The not () method is opposite to the filter () method.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

The JQuery traversal element descendant and compatriot implementation method above is all the content that I have shared with you. I hope to give you a reference, and I hope you can also provide more support for the customer's house.

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.