Javascript DOM HTML Aside Object create

Introduction

The Aside object represents an HTML <aside> element.

We can create an <aside> element by using the document.createElement() method:

var x = document.createElement("ASIDE");

Click the button to create an ASIDE element containing a H4 and P element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>
<script>
function myFunction() {//from w  w w. j a v a  2 s.c  o  m
  var x = document.createElement("ASIDE");
  x.setAttribute("id", "myAside");
  document.body.appendChild(x);

  var heading = document.createElement("H4");
  var txt1 = document.createTextNode("Test");
  heading.appendChild(txt1);
  document.getElementById("myAside").appendChild(heading);

  var para = document.createElement("P");
  var txt2 = document.createTextNode("This is a test. This is a test. This is a test. ");
  para.appendChild(txt2);
  document.getElementById("myAside").appendChild(para);
}
</script>

</body>
</html>



PreviousNext

Related