3

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?

verism
  • 1,106
  • 1
  • 12
  • 35

1 Answers1

4

.css also accepts an object:

$(this).css(circle.includesXY(e.pageX, e.pageY)
   ? {
      property1: 'value1',
      property2: 'value2'
   }
   : {
      property1: 'value3',
      property2: 'value4'
   }
);
Danil Speransky
  • 29,891
  • 5
  • 68
  • 79
Explosion Pills
  • 188,624
  • 52
  • 326
  • 405