I'm not entirely sure how to ask this question. I know there's an answer out there somewhere but I can't for the life of me figure out / remember the terminology for what I'm trying to achieve.
I have profile cards written in HTML, all with the class name "card". Within each card are two numbers. I want to be able to display a progress bar specific to the % relationship of the numbers within each INDIVIDUAL card.
So, my code is:
<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>
What I'm hoping to achieve is for Javascript to acess the cardTarget
and cardCurrent
numbers of nameTitle: NAME 1
, then output a percentage to progBar
of the same card
, and to do the same thing for nameTitle: NAME 2
.
So that progBar
of nameTitle: NAME1
will equal 50%, and progBar
of nameTitle: NAME 2
will equal 25%.
I know how to access the elements, and I know how to do the calculations to convert to a percentage, what I don't know is how to (essentially) bind the elements to card
without affecting other card
because they are all assigned the same classnames.
I hope that makes sense, and thanks in advance for your help.