0

I have a progress bar that is outputted from a webapp program like this:

<div id="diskUsageProgressBar">
    <div class="green-bar" style=" width: 1%;">
    </div>
</div>

And I have added to the page a much nicer bar like this:

<div class="progress xs">
    <div class="progress-bar progress-bar-red diskusgbar" style="width: 1%;"></div>
</div>

How could I use javascript (or JQuery) to copy the width value from the first one and paste it into the second one on page load?

Thanks for the help!

Marc Audet
  • 46,011
  • 11
  • 63
  • 83

5 Answers5

1

jQuery javascript:

$('.progress.xss .diskusgbar').css('width', 
    $('#diskUsageProgressBar .green-bar').css('width')
);
Rob Schmuecker
  • 8,934
  • 2
  • 18
  • 34
0

Like this:

$(function(){
   $('.progress-bar-red').attr('style',$('.green-bar').attr('style'));  
})
Amit Joki
  • 58,320
  • 7
  • 77
  • 95
0

If you want to only copy the width then you can use native .width() method of jquery to get/set value:

$('.progress-bar').width($('.green-bar').width());
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
0

use this

$('.progress-bar').width($('.green-bar').width());
0

First, as said in Is it possible to listen to a "style change" event?

(function() {
var ev = new $.Event('style'),
    orig = $.fn.css;
$.fn.css = function() {
    orig.apply(this, arguments);
    $(this).trigger(ev);
}
})();

And then bind it:

$('#diskUsageProgressBar > .green-bar').bind('style', function(e) {
 $('.progress.xs > .diskusgbar').css('width', 
  $('#diskUsageProgressBar > .green-bar').css('width')
 );
});

Hope it works. Maybe tricky and not so symple if the first bar is in another iframe.

Community
  • 1
  • 1
miguel-svq
  • 2,136
  • 9
  • 11