Javascript DOM HTML Footer Object create

Introduction

We can create a <footer> element via the document.createElement() method:

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

Click the button to create a FOOTER element containing a P element with some text.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {//from   ww w.j a  va  2s .c  o  m
  var x = document.createElement("FOOTER");
  x.setAttribute("id", "myFooter");
  document.body.appendChild(x);

  var y = document.createElement("P");
  var t = document.createTextNode("This is a p element in a footer element.");
  y.appendChild(t);

  document.getElementById("myFooter").appendChild(y);
}
</script>

</body>
</html>



PreviousNext

Related