Javascript DOM HTML Subscript Object get

Introduction

The Subscript object represents an HTML <sub> element.

We can access a <sub> element via document.getElementById():

var x = document.getElementById("mySub");

Click the button to set the color of <sub> element to red.

View in separate window

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

<script>
function myFunction() {//from  w  w w  .ja  va 2 s  . com
  var x = document.getElementById("mySub");
  x.style.color = "red";
}
</script>

</body>
</html>



PreviousNext

Related