Javascript DOM HTML Bold Object create

Introduction

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

Click the button to create a B element with some text.

View in separate window

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

<script>
function myFunction() {/*from www. j ava  2  s.c  o m*/
  var x = document.createElement("B");
  var t = document.createTextNode("Some bold text");
  x.appendChild(t);
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related