- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM nodeName Property
The HTML DOM nodeName property returns a string corresponding to the name of the node.
Following is the syntax −
Returning string value
Node.nodeName
Here, the return value can be the following −
- Tag name in uppercase for element nodes
- Name of the attribute for attribute nodes
- ‘#comment’ for comment nodes
- ‘#document’ for comment nodes
- ‘#text’ for text nodes
NOTE: Whitespaces are considered as text nodes only.
Let us see an example of HTML DOM nodeName property −
Example
<!DOCTYPE html> <html> <head> <title>HTML DOM nodeName</title> <style> form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="button"] { border-radius: 10px; } </style> </head> <body> <form> <fieldset> <legend>HTML-DOM-nodeName</legend> <label for="example">Example site: </label> <input id="urlSelect" type="url" name="urlAddress" value="http://www.example.com" disabled> <input type="button" onclick="getNodeNames()" value="Get all names"> <div id="divDisplay"></div> </fieldset> </form> <script> var urlSelect = document.getElementById("urlSelect"); var commentNode = document.createComment("My Example URL"); urlSelect.appendChild(commentNode); var divDisplay = document.getElementById("divDisplay"); function getNodeNames() { divDisplay.textContent = 'Body: '+document.body.nodeName; divDisplay.textContent += ' & input: '+urlSelect.nodeName; divDisplay.textContent += ' & comment: '+commentNode.nodeName; } </script> </body> </html>
Output
Before clicking ‘Get all names’ button −
After clicking ‘Get all names’ button −
Advertisements