Javascript DOM HTML Mark Object create

Introduction

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

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

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

View in separate window

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

<script>
function myFunction() {/* w  ww  .  j a v  a 2s  .com*/
  var x = document.createElement("MARK");
  var t = document.createTextNode("Some marked text");
  x.appendChild(t);
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related