html - Use jQuery to check percentage width of div and perform conditional style -


i've got ten instances of .progress. of have percentage based widths.

if given instance of .progress on 100% width, i'd style it's backround red , force 100% width.

any help?

this feeble attempt.

if ($( '.progress' ).css("width") > '100%') {      $(this).css('background-color', 'red');      // or $(this).addclass('red');  } 

i think width in % not available in js think should try check target's width parent's width:

if ($('.progress').css("width") >== $('.progress').parent().css("width")) {    $(this).css('background-color', 'red');    // or $(this).addclass('red'); } 

or way:

$('.progress').each(function(){    var $target = $(this);    if ($target.css("width") >== $target.parent().css("width")) {       $target.css('background-color', 'red');       // or $target.addclass('red');    } }); 

or way

$('.progress').css('background-color', function(_, color) {     return $(this).width() > $(this).parent().width() ? 'red' : color; }); 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -