Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple css rules with ternary operator

Within a .hover() event, I have the following code:

$(this).css('background-position', circle.includesXY(e.pageX, e.pageY) ? 'bottom' : '');

Could somebody explain how I can add more property:value pairs to .css() without compromising the ternary operator? If not, how should it be rewritten?

like image 696
verism Avatar asked Apr 02 '26 02:04

verism


1 Answers

.css also accepts an object:

$(this).css(circle.includesXY(e.pageX, e.pageY)
   ? {
      property1: 'value1',
      property2: 'value2'
   }
   : {
      property1: 'value3',
      property2: 'value4'
   }
);
like image 183
Explosion Pills Avatar answered Apr 08 '26 08:04

Explosion Pills



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!