Javascript Reference - HTML DOM Emphasized Object








The Emphasized object represents an HTML <em> element.

Standard Properties and Events

The Emphasized object supports the standard properties and events.

Example

We can access an <em> element by using getElementById().


<!DOCTYPE html>
<html>
<body>
<em id="myEm">this emphasized text</em>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--   w  ww . j  av a2  s.  c o m-->
    var x = document.getElementById("myEm");
    x.style.color = "red";
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

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


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from w  w  w  .  j a  va 2 s  .co m-->
    var x = document.createElement("EM");
    var t = document.createTextNode("emphasized text");
    x.appendChild(t);
    document.body.appendChild(x);
}
</script>
</body>
</html>

The code above is rendered as follows: