javascript - jquery - Changing styling of a class containing a particular child class -
i want height of .pst
increased if contains child class .pa
, code below doesn't work, , if use '.pst'
instead of this
keyword div elements .pst
changes. help!
window.onload = function() { if($('.pst').contents().find('.pa').length !=0){ $(this).css('height','+=200px'); } } <div class="pst"> <div class="pa"></div> <div class="pa"></div> <div class="pa"></div> <div class="pa"></div> </div> <div class="pst"> <div class="pb"></div> <div class="pb"></div> <div class="pb"></div> <div class="pb"></div> </div>
i want height of .pst increased if contains child class .pa
you using $(this) in if condition refers global window object not current .pst
element.
consider using each:
$('.pst').each(function(){ if($(this).find('.pa').length){ $(this).css('height','+=200px'); } });
Comments
Post a Comment