Get Variable Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Variable

Introduction

The Variable object represents an HTML <var> element.

You can access a <var> element by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<var id="myVar">this text</var>

<button onclick="myFunction()">set the color</button>

<script>
function myFunction() {//w ww  .  j  av  a 2 s . c o m
    var x = document.getElementById("myVar");
    x.style.color = "red";
}
</script>

</body>
</html>

Related Tutorials