Javascript Reference - HTML DOM Bold Object








The Bold class represents an HTML <b> element.

Bold Object

The following code shows how to access a <b> element by using getElementById().


<!DOCTYPE html>
<html>
<body>
<b id="myB">bold text</b>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from w  w w.j  a  v  a  2s .co  m-->
    var x = document.getElementById("myB");
    x.style.color = "blue";
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to create a <b> element by using the document.createElement() method.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--  w  w  w .  j a v  a2  s .  c o m-->
    var x = document.createElement("B");
    var t = document.createTextNode("bold text");
    x.appendChild(t);
    document.body.appendChild(x);
}
</script>

</body>
</html>

The code above is rendered as follows:





Standard Properties and Events

The Bold object supports the standard properties and events.