Javascript DOM Body append

Description

Javascript DOM Body append

View in separate window


<!DOCTYPE html>
<head>
<title>Recipe</title>
<script>

window.onload=function() {/*from   ww w  .  j  a v a 2s  . c o  m*/

let body  = document.getElementsByTagName("body")[0]; // body element
let newDiv = document.createElement("div");

// append to body
body.appendChild(newDiv);

newDiv.innerHTML="<p>New element</p>";

}
</script>

</head>
<body>
</body>
</html>



PreviousNext

Related