

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Node name of an HTML element using javascript?
Node name
Javascript has provided document.nodeName to get the node of an element. The name will be fetched by using the id of the particular node.
syntax
document.nodeName();
Example-1
In the following example, a node is given a tag and using that tag, the method document.nodeName() grabs the node name. Here tag doesn't matter, any kind of tag can result as an output.
<html> <body> <div id="dtag">The node name is:</div> <p id="nname"></p> <script> var x = document.getElementById("dtag").nodeName; document.getElementById("nname").innerHTML = x; </script> </body> </html>
Output
The node name is: DIV
Example-2
In the following example, a node is given a tag and using that tag, the method document.nodeName() grabs the node name. Here p tag results as the output.
<html> <body> <p id="ptag">The node namr is:</p> <p id="nname"></p> <script> var x = document.getElementById("ptag").nodeName; document.getElementById("nname").innerHTML = x; </script> </body> </html>
Output
The node name is: p
- Related Questions & Answers
- Value of the class attribute node of an element in JavaScript?
- How to find an element using the attribute “HTML tag name” in Selenium?
- How to get HTML content of an element using jQuery?
- How to set HTML content of an element using jQuery?
- How to set the name of the element in HTML?
- Remove the child node of a specific element in JavaScript?
- How can I remove a child node in HTML using JavaScript?
- Adding an element in an array using Javascript
- Finding nth element of an increasing sequence using JavaScript
- How to add a class name to an element with JavaScript?
- How to remove a class name from an element with JavaScript?
- How can I select an element by tag name using jQuery?
- Find the middle element of an array using recursion JavaScript
- How to show node name in Matplotlib graphs using networkx?
- How to remove all the attributes of an HTML element using jQuery?
Advertisements