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?

1 Answer 1

4

.css also accepts an object:

$(this).css(circle.includesXY(e.pageX, e.pageY)
   ? {
      property1: 'value1',
      property2: 'value2'
   }
   : {
      property1: 'value3',
      property2: 'value4'
   }
);
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, thank you. Now I know the syntax, I should find out exactly what this means :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.