HOW TO ADD NEW ELEMENTS DYNAMICALLY?

Amit Singh

Total Post:565

Points:2825
Posted by  Amit Singh
 1872  View(s)
Ratings:
Rate this:
  1. Amit Singh

    Post:565

    Points:2825
    How to Add new elements dynamically?

    Example:
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <title>Title of page</title>
    <script type="text/javascript">
    function addNode() {
    var newP = document.createElement("p");
    var textNode = document.createTextNode(" I'm a new text node");
    newP.appendChild(textNode);
    document.getElementById("firstP").appendChild(newP);
    }
    </script>
    </head>
    <body onload="addNode();" style=" background: url('../images/Sand-1280.jpg'); background-color: yellow;">
    <p id="firstP">firstP<p>
    </body>
    </html>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!