I've got a number set up in my document like this
and using javascript, I'm pulling the value of that using
What I'm trying to do is pull the value inside of the span tags (0), and then add it to something else (10) to spit out a final value inside of that span tag. This is being called multiple times, so it needs to pull what's in there currently, add 10 to it, and then set the innerHTML to the new value.
The problem is I can't get it to do this correctly. My first thought was the 0 it's pulling from the span tags is being pulled as a string because it would spit out something like "010" and if i added another one, say 20, to it then it would spit out "01020" and so on. I've tried using Number() and parseInt() to convert it to a number, add them, and put it back out there.
Does anyone know if I'm just doing something wrong or missing out on some great function that will take care of this? Thanks!
Code:
<span id="anID">0</span>
Code:
var theValue = document.getElementById("anID");
theValue.innerHTML = theValue.innerHTML + 10;
The problem is I can't get it to do this correctly. My first thought was the 0 it's pulling from the span tags is being pulled as a string because it would spit out something like "010" and if i added another one, say 20, to it then it would spit out "01020" and so on. I've tried using Number() and parseInt() to convert it to a number, add them, and put it back out there.
Does anyone know if I'm just doing something wrong or missing out on some great function that will take care of this? Thanks!
Comment