Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to display the percentage of progress bar

So I’m trying to display the percentage of each bar on one page, here is the HTML for my progress bars:

<div class="col-md-5">
<p>Progress bar1</p>
  <div class="progress progress-striped active">
 <div class="progress-bar progress-bar-Success" style="width: 50%;"></div>
 </div>
 <p>Progress bar2</p>
 <div class="progress progress-striped active">
 <div class="progress-bar progress-bar-Success" style="width: 20%;"></div>
 </div>
 <p>Progress bar3</p>
 <div class="progress progress-striped active">
 <div class="progress-bar progress-bar-Success" style="width: 30%;"></div>
 </div>

and this is my js function

$(document).ready(function() {
 $(".progress-bar").each(function(index) {
//if(index >=0 && index<=1)
//{
$(this).animate({
  width: Math.floor((Math.random() * 100) + 1) + "%"
}, 2500);

//        }
})
});

using this i get all bars are automated generated, but i want to display the percentage of each bar, how i can do this ?
This the fiddle

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

As you using Bootstrap 3, you can add the percentage to the ".progress-bar" div:

Bootstrap docs

$( document ).ready(function() {
    $(".progress-bar").each(function (index ) {
        //if(index >=0 && index<=1)
        //{
            var percent = Math.floor((Math.random() * 100) + 1) + "%";
            $(this).html(percent);
            $(this).animate({width: percent}, 2500);
             
//        }
    })
}); 

Your jsfiddle extended

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading