How to use parentElement in JS
This article mainly shows you "how to use parentElement in JS". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "how to use parentElement in JS".
ParentElement matches cases where parent is element, while parentNode matches cases where parent is node. Element is included in node, and its nodeType is 1.
The usage of parentElement in JS
one
two
three
four
Function xx (a)
{
Alert (a)
}
/ / what's wrong with outputting undefined? Isn't it supposed to output b?
Change to this.parentElement.parentElement.parentElement.parentElement.name correct output
In fact, the code should be understood this way.
Differences between parentNode,parentElement in Js
ParentNode has the same function as parentElement, and childNodes has the same function as children. But parentNode and childNodes are in line with W3C standards, which can be said to be more general. The other two are only supported by IE, not standards, and Firefox does not support them.
The above is all the contents of the article "how to use parentElement in JS". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!