Of course, there are many methods, but I personally think that judging whether an element is a child element of another element is one of the simplest ways to implement it.
Stop talking nonsense and get straight to the method:
function isParent (obj,parentObj){
while (obj != undefined && obj != null && obj.tagName.toUpperCase() != 'BODY'){
if (obj == parentObj){
return true;
}
obj = obj.parentNode;
}
return false;
}
View demo:
http://demo. jb51.net/js/2012/isParent/ Thank you hafeyang for your message. There are also methods related to js to determine whether an element is a child element of another element. There is also the contains method. You can read Situ Zhengmei’s article
http://www.jb51.net/article/26158.htmStatement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn