Create a Span Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Span


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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<button onclick="myFunction()">create a SPAN element</button>

function myFunction() {/*  w w  w .  j a  v  a2s. co  m*/
    var x = document.createElement("SPAN");
    var t = document.createTextNode("This is a span element.");


Related Tutorials