Check if an element is a child of a parent

后端 未结 7 897
故里飘歌
故里飘歌 2020-12-07 19:54

I have the following code.



    

        
7条回答
  •  无人及你
    2020-12-07 20:15

    If you have an element that does not have a specific selector and you still want to check if it is a descendant of another element, you can use jQuery.contains()

    jQuery.contains( container, contained )
    Description: Check to see if a DOM element is a descendant of another DOM element.

    You can pass the parent element and the element that you want to check to that function and it returns if the latter is a descendant of the first.

提交回复
热议问题