JavaScript Document own method: createElement()
[this page | pdf | back links]
The createElement() method (when applied
to the document object of the JavaScript
DOM) creates
a HTML element node.
 
It
has the following syntax with the following parameters. It returns an
element object, representing the created element.
 
document.createElement(nodetype)
 
 
  | Parameter | Required / Optional | Description | 
 
  | nodetype | Required | String specifying the
  name (type) of element to be created | 
 
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");
x.appendChild(txt);
document.getElementById("element").appendChild(x);
</script>
</body>
</html>
 | 
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
| function isSupportedJavaScriptMethodDomCreateElement() {
  return !!document.createElement;
} | 
NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)