Answer the question
In order to leave comments, you need to log in
How can you process a large number of css classes, for example in a loop, in JS?
There are n-number of blocks with progress bars on the page.
Each strip has its own css class of the format pr_1, pr_2, pr_3, etc., containing the width value as a percentage.
The task is to display the css value as a percentage on the strip.
I solved the problem with the following code:
HTML:
<div class="pole">
<div class="progress pr_1">
<p class="p-01"></p>
</div>
</div>
.pr_1 {width: 22%}
.pr_2 {width: 33%}
$(function pr_01 () {
$('.pole').hide();
var w1 = $('.pr_1').width();
var w2 = $('.pr_1').css('width');
var text = $('.p-01');
$('.pole').show();
text.text("ROI: " + w2)
});
$(function pr_02 () {
$('.pole').hide();
var w1 = $('.pr_2').width();
var w2 = $('.pr_2').css('width');
var text = $('.p-02');
$('.pole').show();
text.text("ROI: " + w2)
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question