Check if an element is a child of a parent

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

I have the following code.



    

        
相关标签:
7条回答
  • 2020-12-07 20:27

    .has() seems to be designed for this purpose. Since it returns a jQuery object, you have to test for .length as well:

    if ($('div#hello').has(target).length) {
       alert('Target is a child of #hello');
    }
    
    0 讨论(0)
提交回复
热议问题