Create an Emphasized Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Emphasized

Introduction

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">create an EM element with some text</button>

<script>
function myFunction() {/*w  w  w  .j a v  a2 s.  co  m*/
    var x = document.createElement("EM");
    var t = document.createTextNode("Some emphasized text");
    x.appendChild(t);
    document.body.appendChild(x);
}
</script>

</body>
</html>

Related Tutorials