Use the ternary operator:
$(currentElement).css('opacity', currOp == 1 ? 0.5 : 1);
As a side note: I am used to using ===
over ==
to avoid accidental mistakes by unintended type coercion. To use it here, I would parse currOp
to a number via +
:
$(currentElement).css('opacity', +currOp === 1 ? 0.5 : 1);
For more information, have a look here.