Check if div is descendant of another

后端 未结 4 625
灰色年华
灰色年华 2020-12-13 18:04

Best way to find out if element is a descendant of another there is another question, very similiar to this one but its jquery.

so, how do I do it in js ? I have di

4条回答
  •  天命终不由人
    2020-12-13 18:51

    // x is the element we are checking
    while (x = x.parentNode) { 
        if (x.id == "a") console.log("FOUND");
    }
    

提交回复
热议问题