javascript - Change color of child element if specific condition is satisfies -


i change color of child element if has "out of stock message". message generated @ run time, can changed other items , want change color if text "out of stock". can not modify code can apply css or javascript / jquery. here html code:

<span id="stockstatus" class="status">      <span id="itemavail">out of stock</span> </span> 

i have tried jquery code not working:

$(document).ready(function () {     $(".status").each(function(){         if ($(this).children('span').text().trim() == "out of stock") {             $(this).children('span').css("color", "red");         }      }); }); 

after changing content(you have not mentioned how getting added on page), can use:

$(".status span:contains(out of stock)").css("color", "red"); 

working demo


Comments

Popular posts from this blog

javascript - Wordpress slider, not displayed 100% width -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -