JavaScript Document own method: createComment()
[this page | pdf | back links]
The createComment() method (when applied
to the document object of the JavaScript
DOM) creates a comment node.
 
It
has the following syntax with the following parameters. It returns a comment
object.
 
document.createComment(text)
 
 
  | Parameter | Required / Optional | Description | 
 
  | text | Optional | The text to include in
  the comment object | 
 
EXAMPLE:
HTML USED IN THIS EXAMPLE:
| <!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body>
Created using JavaScript:<br><br>
<span id="element"></span>
<script>
var x = document.createElement("EM");
var txt = document.createTextNode("italic text");
var ctxt = document.createComment("here is a comment");
x.appendChild(txt);
x.appendChild(ctxt);
document.getElementById("element").appendChild(x);
</script>
</body>
</html>
 | 
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
| function isSupportedJavaScriptMethodDomCreateComment() {
  return !!document.createComment;
} | 
NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)