- Trending Categories
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
Value of the class attribute node of an element in JavaScript?
Javascript has provided the getAttributeNode() method to find the attribute node with the specified name of an element, as an attribute object. If the attribute does not exist, the return value is null or an empty string ("").
syntax
element.getAttributeNode(attributename);
It returns the attribute object representing the specified attribute node
Example
In the following example, there are two heading tags with different classes. Those tags when accessed by the getAttributeNode() can return the attribute class with which they attached. It works the same as an array. We can access the multiple classes only by providing their index numbers.
<html> <body> <h2 class="class1">Tutorix</h2> <h2 class="class2">Tutorialspoint</h2> <p id = "attribute"></p> <script> var elmnt = document.getElementsByTagName("h2")[1]; var value = elmnt.getAttributeNode("class").value; document.getElementById("attribute").innerHTML = value; </script> </body> </html>
Output
Tutorix Tutorialspoint class2
Advertisements