The Variable object represents an HTML <var> element.
We can access a <var> element via document.getElementById()
:
var x = document.getElementById("myVar");
Click the button to set the color of <var> element to red.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <var id='myVar'>test</var> <script> function myFunction() {/* w w w .j a v a2 s.co m*/ var x = document.getElementById("myVar"); x.style.color = "red"; } </script> </body> </html>