I'm getting an error message on this function telling me that parseInt doesn't have a radix parameter, even though I'm passing it the variable moveCount. I assume this means that the value of the span with the id #moveCount is not being assigned to the variable moveCount. I've marked the line below where I think the problem's arising. I've tried this line
moveCount = $('span #moveCount').html();
both with and without using the word 'span' in the selector and am getting the same result.
function incrementMoveCount() {
//gets the html of the span with id
//moveCount
//turns it into a number
//increments it by one
//sets the html of the span with id moveCount
//to the new move count
var moveCount = 0;
var newMoveCount = 0;
moveCount = $('span #moveCount').html(); # problem here
newMoveCount = parseInt(moveCount);
newMoveCount = newMoveCount + 1;
$('span #moveCount').html('newMoveCount');
}
html
<div id="meta">
<h1>Checkers</h1>
<h4>Moves: <span id="moveCount">0</span></h4>
</div>
You can remove the space if it's the span's id - space specifies descendants.. so you are actually looking for descendants of span with an id=moveCount
$('span#moveCount').html();
Or since you are selecting by ID you don't need to specify span as ID selector is the fastest - ID's are unique so it will always look for the first element with that id
$('#moveCount').html();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With