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:
xxxxxxxxxx
1
var commentNode = document.createComment('Example comment text...');
In this example, we use document.createComment()
to create a comment node dynamically and then append it to the document.body
.
xxxxxxxxxx
1
2
<html>
3
<body>
4
<script>
5
6
var commentNode = document.createComment('Example comment text...');
7
8
document.body.appendChild(commentNode);
9
10
console.log(document.body.outerHTML);
11
12
</script>
13
</body>
14
</html>