Determines whether an element is a child or parent element of another element.

Source: Internet
Author: User

Determines whether an element is a child or parent element of another element.

Determine whether an element is a child or parent element of another element:
In practical applications, it is sometimes determined that an element is a child element or a parent element of another element. The following describes how to use a code example.

// Determine whether the current element is the child element of the filtered element jQuery. fn. isChildOf = function (B) {return (this. parents (B ). length> 0) ;}; // determines whether the current element is a child element or jQuery. fn. isChildAndSelfOf = function (B) {return (this. closest (B ). length> 0 );}

The above code can meet our requirements. The code is relatively simple. We will not introduce it much here. If you have any questions, please leave a message.
Related reading:
1. For the parents () function, see section 1 of parents () method of jQuery.
2. For details about closest functions, refer to jQuery's closest () function.

The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 9042.

For more information, see: http://www.softwhy.com/jquery/

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.