Reputation: 5986
I'm writing a jQuery plugin and I am trying to do this:
$(this).height>=options.maxHeight ?
$(this).css({overflow:"auto"}) :
$(this).css({overflow:"hidden"})
however it's not working, I have used this method in my javascript before.
This works how it should, just i was trying to use little code as possible.
if($(this).height()>=options.maxHeight)
{
$(this).css({overflow:"auto"});
}
else
{
$(this).css({overflow:"hidden"});
}
Upvotes: 0
Views: 128
Reputation: 707466
Change it to:
$(this).height() >= options.maxHeight ?
$(this).css({overflow:"auto"}) :
$(this).css({overflow:"hidden"})
You forgot the ()
in .height()
.
You could also use this:
$(this).css({overflow: $(this).height() >= options.maxHeight ? 'auto' : 'hidden'});
Upvotes: 1