0

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.

1
  • 1
    span elements don't have value attributes Commented Mar 26, 2013 at 13:30

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks a bunch for this - wait going a bit crazy without knowing this!
Not sure why this answer is getting more upvotes? I posted my answer first... :P
I'm just cuter than a wrench :D
actually i posted 1st, but was waiting for 3 minutes delay
Hmm.. I guess we are at the mercy of sof's algorithm here
1

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.