JavaScript nodeName Property Tutorial

In this section, we will learn what the Element nodeName property is and how to use it in JavaScript.

What is Element nodeName Property in JavaScript?

The JavaScript Element nodeName property is used to get the name of the target element that invoked the property.

Note: in the “return value” part of this section, you’ll see that depending on the type of node that this property is called with, we might get a different value.

JavaScript nodeName Property Syntax:

element.nodeName;

JavaScript nodeName Property Input Value

The nodeName property is read-only and so we can’t assign a value to it.

JavaScript nodeName Property Return Value

Depending on the type of the node, the return value of this property might be:

Node Type

nodeName return value

Element

Element name

Attr

Attribute Name

Text

#text

CDATASection

#cdata-section

EntityReference

Entity reference name

Entity

Entity name

ProcessingInstruction

Target

Comment

#comment

Document

#document

DocumentType

Doctype name

DocumentFragment

#document fragment

Notation

Notation name

Example: JavaScript get element name

See the Pen JavaScript get element name by Omid Dehghan (@odchan1) on CodePen.

Leave a Reply