html - Having trouble changing a number inside span tags using a javascript function -


Edit: Thank you! It works perfectly now, I appreciate the quick response!

The relevant jumble.

I have a list of spaces, with each unique ID, that I want to be able to modify using a href or input (either will work). I am trying to work now, but it is not available anywhere. Related HTML is:

  & lt; Ul & gt; & Lt; Li & gt; STR & lt; Span id = "str" ​​& gt; 0 & lt; / Span & gt; & Lt; / Li & gt; & Lt; Br> & Lt; Input type = 'button' onClick = "abilUp ()" value = 'increase from 1' / & gt;  

And the relevant javascript is:

  var statVal = 1; Function abilUp () {var aV = + document.getElementById ('str'); AV = AV + Statewise; Console.log ("str =" + aV); }  

The button works, and the function is increasing in the console, but the actual value is not changing within the period. I am pretty sure that it is not identified as 0, so I have tried to use the following:

  + document.getElementById ('str'); Number (document.getElementById ('str')); ParseInt (document.getElementById ('str'), 10);  

I have tried to use a variable with the inner HTML, and it is not working, I know that it is possible, I do not know what I'm doing wrong I am

>

The problem is that You are in the element variable aV no value, so you have to get the content in that element and take action on it.

Try it

  var statVal = 1; Function abilUp () {var aV = document.getElementById ('str'); AV.textContent = (+ aV.textContent) + statVal; Console.log ("str =" + aV.textContent); }  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -