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

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -