Create a Bold Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Bold

Introduction

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">create a B element with text</button>

<script>
function myFunction() {/*  w w  w.  ja v  a2s. co  m*/
    var x = document.createElement("B");
    var t = document.createTextNode("Some bold text");
    x.appendChild(t);
    document.body.appendChild(x);
}
</script>

</body>
</html>

Related Tutorials