The createElement()
method creates an element node.
document.createElement()
Parameters
Parameter |
Description |
type |
Required. |
Type |
Description |
Node |
The created element node. |
createTextNode()
method creates a text node.
document.createTextNode(text)
Parameter | Description |
text |
Required. The text for the node. |
Type | Description |
Node | The created text node. |
The createComment()
method creates a comment and
returns the comment node.
document.createComment(text)
Parameter | Description |
text |
Optional. The comment text. |
Type | Description |
Node | The created comment node. |
<!DOCTYPE html>
<html>
<head>
<title>DOM Navigation</title>
<style>
h1{
text-align: center;
color:#ff0000;
}
</style>
</head>
<body>
<h1>Yahoo Baba : DOM Create Methods</h1>
<script src="js/dom-create.js"></script>
</body>
</html>
//var newElement = document.createElement("p");
var newElement = document.createElement("h2");
console.log(newElement);
var newText = document.createTextNode("This is just text");
console.log(newText);
/* Dom Create Comment*/
var newComment = document.createComment("this is comment");
console.log(newComment);