Javascript DOM HTML Underline Object create

Introduction

We can create a <u> element via the document.createElement() method:

var x = document.createElement("U");

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

View in separate window

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

<script>
function myFunction() {/* w  w w  .j  a  v  a  2s .  co  m*/
  var x = document.createElement("U");
  var t = document.createTextNode("This text is underlined");
  x.appendChild(t);
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related