Javascript DOM HTML Emphasized Object create

Introduction

We can create an <em> element via the document.createElement() method:

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

Click the button to create an EM element with some text.

View in separate window

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

<script>
function myFunction() {//from ww  w. j  av  a2s. c  om
  var x = document.createElement("EM");
  var t = document.createTextNode("Some emphasized text");
  x.appendChild(t);
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related