EN
JavaScript - create comment dynamically
0
points
In this article, we would like to show you how to create comment dynamically using JavaScript.
Quick solution:
var commentNode = document.createComment('Example comment text...');
Practical example
In this example, we use document.createComment() to create a comment node dynamically and then append it to the document.body.
// ONLINE-RUNNER:browser;
<!doctype html>
<html>
<body>
<script>
var commentNode = document.createComment('Example comment text...');
document.body.appendChild(commentNode);
console.log(document.body.outerHTML);
</script>
</body>
</html>