EN
JavaScript - check if node is comment type
0
points
In this article, we would like to show you how to check if a node is a comment type using JavaScript.
Quick solution:
myNode.nodeType === Node.COMMENT_NODE;
Practical example
In this example, we dynamically create comment element and compare it to the Node.COMMENT_NODE returning boolean value.
// ONLINE-RUNNER:browser;
<!doctype html>
<html>
<body>
<script>
const comment = document.createComment('This is example comment...');
console.log(comment.nodeType === Node.COMMENT_NODE); // true
</script>
</body>
</html>