Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use parentElement in JS

Shulou Source: shulou.com Published: 2022-06-03 11:01:42 09月25日 Update

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!

Tags: Content article output function situation standard learning help support two between code just easy to understand more organization knowledge editing industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei macOS Shulou Tech Info Xiaomi Microsoft