I'm struggling to articulate my question, but I know there's a solution out there. I have profile cards in HTML, each with the class "card" containing two numbers. My goal is to display a progress bar specific to the % relationship of these numbers within EACH individual card.
Here's an example of my code:
<div class="card">
<p class="nameTitle">NAME 1</p>
<p class="cardTarget">20</p>
<p class="cardCurrent">10</p>
<div class="progBar"></div>
</div>
<div class="card">
<p class="nameTitle">NAME 2</p>
<p class="cardTarget">20</p>
<p class="cardCurrent">5</p>
<div class="progBar"></div>
</div>
I want Javascript to access the cardTarget
and cardCurrent
for nameTitle: NAME 1
, then calculate a percentage and output it to progBar
of that same card
. This should be done for each card like nameTitle: NAME 2
.
This means the progBar
for nameTitle: NAME 1
should be set at 50%, and for nameTitle: NAME 2
it should be at 25%.
I understand how to access elements and perform calculations for percentages, but what I'm struggling with is how to bind these elements to each card
individually without affecting other cards since they share the same class names.
I hope this explanation is clear, and thank you in advance for your assistance.