How to use JavaScript Dom Node hasAttributes
In this article I have described about Dom Node hasAttributes() method in javaScript
JavaScript Dom Node hasAttributes() method
- As we already know that node object is used to represent and add node within the HTML document.
- The hasAttributes() method checks whether any node has an attribute or not and return boolean value.
- It returns true if there is any node has an attribute otherwise false.
Browser support
Following are the main browsers which support the hasAttributes() method of Dom Node object
- Internet Explorer.
- Firefox.
- Opera.
- Google Chrome.
- Safari.
NOTE - Internet Explorer 8 doesn't support this method.
Syntax
The hasAttributes() of Dom Node object has following syntax
node.hasattributes()
Lets take an example
<!DOCTYPE html>
<html>
<body style ="background-color:green">
<p id="MENU">CHECK AN ELEMENT HAS AN ATTRIBUTE OR NOT</p>
<button onclick="myFunction()">CHECK</button>
<script type="text/javascript">
function myFunction()
{
var x = document.getElementById("MENU");
x.innerHTML = document.body.hasAttributes();
}
</script>
</body>
</html>
|
Output
When we click on button
Further Readings
You may also want to read these related articles :here
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here