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