Create a Code Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Code

Introduction

You can create a <code> element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>



<button onclick="myFunction()">create a CODE element with some text</button><br><br>

<script>
function myFunction() {//from w w  w.  j a  v  a  2  s  . co m
    var x = document.createElement("CODE");
    var t = document.createTextNode("this is a test");
    x.appendChild(t);
    document.body.appendChild(x);
}
</script>

</body>
</html>

Related Tutorials