Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • createElement() Method in JavaScript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 115
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: