Home > Web Front-end > JS Tutorial > body text

js code to determine whether an element is a child element of another element_javascript skills

WBOY
Release: 2016-05-16 17:54:58
Original
1501 people have browsed it

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:

Copy code The code is as follows:

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 articlehttp://www.jb51.net/article/26158.htm
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template