How to find out if a element belongs to a parent, javascript
Here is a function to find out if an element belongs to a particular parent.
- We have 2 parameters (the element id, the parent id(string))
- We find the direct parent of that element
- assign the element to the parent
- if the new element equals the parent string passed through, then return true
- If the parent is not found after walking through the DOM, then return false
function checkParent(element, parent){
while(element.parentNode){
element=element.parentNode;
if(element.id==parent){return true;}
}
return false;
}
About this entry
You’re currently reading “How to find out if a element belongs to a parent, javascript,” an entry on Dazzatechfind's Blog
- Published:
- May 22, 2010 / 11:34 am
- Category:
- javascript
- Tags:
- elements, find parent, javascript
No comments yet
Jump to comment form | comment rss [?] | trackback uri [?]