Get Span Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Span


The Span object represents an HTML <span> element.

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<span id="mySpan" style="color:blue;">blue</span

<button onclick="myFunction()">get the color of the span element</button>

<p id="demo"></p>

function myFunction() {// w  ww  .j a v  a2 s. c  o m
    var x = document.getElementById("mySpan").style.color;
    document.getElementById("demo").innerHTML = x;


Related Tutorials