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/