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

Source: Internet
Author: User

Determines whether an element is a child or parent element of another element:
In practice, it is sometimes judged that an element is a child or parent element of another element, as described in the code example below.

    jquery.fn.ischildof= function (b) {return (this. Parents (b)  ). length>0//jquery.fn.ischildandselfof=function(b) {    return (this. Closest (b). Length>0);}

The above code can achieve our requirements, the code is relatively simple here is not much introduction, if there are any questions can be thread message.
Related reading:
The 1.parents () function can be found in the parents () method section of jquery .
The 2.closest function can be found in the closest () function section of jquery .

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

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

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

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.