I often repeat this type of code:
if ($(this).val() == 'X') { $('#something').show(); }
else { $('#something').hide(); }
I'm not crazy about the fact that $ ('# something') appears twice. Is there a more elegant way to express it?
[Update] I formulated the question poorly - I'm looking for a general solution, not just show / hide (and therefore switch). For the general case of taking different actions on the selected element (s) based on the conditional, is there a more elegant design?
source
share