Javascript DOM Element Create

Description

Javascript DOM Element Create

View in separate window


<!DOCTYPE html> 

<html lang="en"> 
<body> 
    <script> 
        let newText = document.createTextNode("My Heading"); 
        let newElem = document.createElement("h1"); 

        newElem.appendChild(newText); //from ww  w .  j a  v a  2 s  . co  m
        document.body .appendChild(newElem); 

        newText = document.createTextNode("This is some text in a paragraph"); 
        newElem = document.createElement("p"); 

        newElem.appendChild(newText); 
        document.body .appendChild(newElem); 
    </script> 
</body> 
</html> 



PreviousNext

Related