I'm working on a meter that goes up or down depending on decisions you make.
I'm doing this by changing the width percentage of the CSS with jQuery.
Currently I can set it to an arbitrary percent, but I want to add or subtract a percentage from the current value.
How would I do this?
My code:
$("#meter").css("width", "40%");
$(".fan-percent").text("40%");
My HTML:
<div id="fanHappiness">
<h4 class="white">Fan Happiness:</h4>
<div id="meter">
<h4 class="white fan-percent">50%</h4>
</div>
Thanks.
UPDATE:
Using this code I've gotten it too work, but it only subtracts or adds from the original number, so if I add 25 to the original 50, then subtract 25, I don't get 50, I get 25. Maybe storing the number in a variable after retrieving it from the CSS would help.
$("#meter").width($("#meter").width() + 25);
$(".fan-percent").text($(".fan-percent").width() + 25 + "%");