The Mark object represents an HTML <mark> element.
The Mark object supports the standard properties and events.
We can access a <mark> element by using getElementById().
<!DOCTYPE html>
<html>
<body>
<mark id="myMark">this marked text</mark>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!-- ww w . j av a2 s. c om-->
var x = document.getElementById("myMark");
x.style.fontSize = "x-large";
x.style.color = "blue";
}
</script>
</body>
</html>
The code above is rendered as follows:
We can create a <mark> element by using the document.createElement() method.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<!-- www.j a v a 2 s .com-->
<script>
function myFunction() {
var x = document.createElement("MARK");
var t = document.createTextNode("this is a test");
x.appendChild(t);
document.body.appendChild(x);
}
</script>
</body>
</html>
The code above is rendered as follows: