Testing objects for ancestor/descendent relationship in JavaScript or Jquery

后端 未结 3 1443
-上瘾入骨i
-上瘾入骨i 2020-12-09 17:21

I\'m trying to come up with a reusable JS or jQuery function that would allow me to test if one object is a DOM descendant of another.

I\'ve seen a model of testing

3条回答
  •  心在旅途
    2020-12-09 17:46

    In jQuery ancestors using jQuery objects I suggested

    if ($(obj1).parents().index($(obj2)) >= 0) {
        // obj1 is a descendant of obj2
    }
    

提交回复
热议问题