JasonB
JasonB

Reputation: 565

Updating a value of a <span> using Javascript getElementById

I am very new to JS and trying to get my head around how to change values of a span using JS. So, I have a span looking like this:

<span id="s551392614400915" class="vote-count-post" value="551392614400915">0.31</span>

I would like to change the 0.31 to say 150 - and Iam trying to use the getElementById as follows:

var xx=150;
document.getElementById("s551392614400915").value = "150"; //dosent work.
//document.getElementById("s551392614400915").value = xx; //dosent work.

for some reason this does not seem to work. I know I am doing something completely stupid, but I am unable to see where. Here is my rather silly JS Fiddle

any help with this would be great.

Upvotes: 0

Views: 68

Answers (2)

Artyom Neustroev
Artyom Neustroev

Reputation: 8715

Use document.getElementById("s551392614400915").innerHTML= "150" if you want to change the contents of the span.

Upvotes: 2

Elliot Bonneville
Elliot Bonneville

Reputation: 53311

Use innerHTML instead of value. value is used for form inputs with a user-changeable value.

document.getElementById("s551392614400915").innerHTML = "150";

Upvotes: 1

Related Questions