I’m trying to update the html content of a span element with the summation of some other spans with classes that can be toggled but the jQuery each() methods do not return the current list of checked items but is only set to the previous ones checked. My code below
function total() {
var tot = parseInt($("#amount span").text(), 10);
$(".green").each(function(){
tot += parseInt($(this).html().trim().substr(1));
});
return tot;
}
$(".money").click(function() {
$(this).toggleClass("green");
// Update total amount
$("#amount span").text(total());
});
[quote=“nmeri17, post:1, topic:231665, full:true”]
I’m trying to update the html content of a span element with the summation of some other spans with classes that can be toggled but the jQuery each() methods do not return the current list of checked items but is only set to the previous ones checked.[/quote]
What is the expected behaviour?
For example:
when the first is one red and the second one is green
click on the red, which has two results:
the first one also turns green so that both are green