EN
JavaScript - check if node is element type
0
points
In this article, we would like to show you how to check if a node is an element type using JavaScript.
Quick solution:
myNode.nodeType === Node.ELEMENT_NODE;
Practical example
In this example, we check if the node is an element type by getting a handle to myDiv element and comparing it to the Node.ELEMENT_NODE returning boolean value.
// ONLINE-RUNNER:browser;
<!doctype html>
<html>
<body>
<div id="my-div">Example text...</div>
<script>
var myDiv = document.querySelector('#my-div');
console.log(myDiv.nodeType === Node.ELEMENT_NODE); // true
</script>
</body>
</html>