I have a project involving a meter that changes based on decision outcomes.
To achieve this, I am adjusting the width percentage using jQuery and CSS.
Currently, I can set it to a specific percent, but I need help in adding or subtracting a percentage from the current value.
Any suggestions on how to do this?
This is my code snippet:
$("#meter").css("width", "40%");
$(".fan-percent").text("40%");
Here's my HTML setup:
<div id="fanHappiness">
<h4 class="white">Fan Happiness:</h4>
<div id="meter">
<h4 class="white fan-percent">50%</h4>
</div>
Thank you for any assistance.
UPDATE:
While the following code somewhat works, it only adjusts the number relative to the original value. For instance, adding 25 then subtracting 25 from the original 50 results in 25 instead of 50. Storing the value in a variable after retrieving it from the CSS might resolve this issue.
$("#meter").width($("#meter").width() + 25);
$(".fan-percent").text($(".fan-percent").width() + 25 + "%");