Skip to content Skip to sidebar Skip to footer

How To Style Only This Element If Condition Is True Or False?

I'm trying to write jQuery that will loop over every div with the class name .content_txt and check its height is over 60px. If true, then set that element to height:auto; if false

Solution 1:

height of jquery is function and not property. so use .height():

if($(this).height() > 60){
    //rest code
 }

Solution 2:

$('.content_txt').each(function(){
     if($(this).height() > 60){
       $(this).css('height','auto');
     }else{
       $(this).css('height','60px');        
     }
});

height()

Solution 3:

height is a function and not a property.

So, you have to do if($(this).height() > 60){}

Post a Comment for "How To Style Only This Element If Condition Is True Or False?"