$(function() {
var div = $('div');
$('input').click(function() {
if($(this).is(':checked')) {
div.html(div.text() += 49);
} else {
div.html(div.text() -= 49);
}
});
});
This is crazy, for some reason the += and -= flag up bad assignment, why so?
By the way, I’m not using this code for anything, I know its bad, I’m just testing the +=
Example! http://jsfiddle.net/dD73X/
You cannot assign something to a temporary result. Use
+and-instead. Also, there would be no need to assign with the compound operators becausediv.html(...)does exactly that: it replaces the text of the div with the result of the addition/subtraction.Update: It seems that you also want to do integer addition (instead of string concatenation). You ‘d need to include
parseIntas well for that, making the code: