Get Code Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Code

Introduction

The Code object represents an HTML <code> element.

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<code id="myCode">test</code>

<button onclick="myFunction()">set the color of the code element to red</button>

<script>
function myFunction() {//ww w .j av  a2  s .co m
    var x = document.getElementById("myCode");
    x.style.color = "red";
}
</script>

</body>
</html>

Related Tutorials