Create a Code Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Code


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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

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

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");


Related Tutorials