Get Span Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Span

Introduction

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>
<html>
<body>

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

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

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

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

</body>
</html>

Related Tutorials