Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

이 문서는 아직 자원 봉사자들이 한국어로 번역하지 않았습니다. 함께 해서 번역을 마치도록 도와 주세요!

The Node.nodeName read-only property returns the name of the current node as a string.

The returned values for different types of nodes are:

Interface nodeName value
Attr The value of Attr.name
CDATASection "#cdata-section"
Comment "#comment"
Document "#document"
DocumentFragment "#document-fragment"
DocumentType The value of DocumentType.name
Element The value of Element.tagName
Entity The entity name
EntityReference The name of entity reference
Notation The notation name
ProcessingInstruction The value of ProcessingInstruction.target
Text "#text"

Syntax

var str = node.nodeName;

Example

Given the following markup:

<div id="d1">hello world</div>
<input type="text" id="t"/>

and the following script:

var div1 = document.getElementById("d1");
var text_field = document.getElementById("t");

text_field.value = div1.nodeName;

In XHTML (or any other XML format), text_field's value would read "div". However, in HTML, text_field's value would read "DIV", because nodeName and tagName return in upper case on HTML elements in DOMs flagged as HTML documents. Read more details on nodeName case sensitivity in different browsers.

Note that tagName property could have been used instead, since nodeName has the same value as tagName for an element. Bear in mind, however, that nodeName will return #text for text nodes while tagName will return undefined.

Specifications

문서 태그 및 공헌자

태그: 
 최종 변경: fscholz,