Question

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"});
}
Était-ce utile?

La solution

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'});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top