createElement() Method in JavaScript is used to create a HTML element through the JavaSript
The Syntax is as:
var element = document.createElement(tagName);
the Tag name in statement defines the HTML element to be created. for the same purpose the createElement() is used.
in a larger scale we can make option in the select box options using the same method as :
var select = document.getElementById("selectbox");
var option = document.createElement('option');
option.text = "XYZ";
select.add(option);
In the above code we have first selected the Element select box by its Id selectbox and created an object of the select box as select. Then we have created an HTML element option by using the method createElement() and the method been passed by the HTML tag name. afterwards in the end we have added the tag to the select box. same way any HTML Element can be created.
0 Comment(s)