How would one shorten the following using ternary operators?
if ((pos - maxPos) == (c.clientWidth)) {
$j("#next").addClass("filter");
} else {
$j("#next").removeClass("filter");
}
How would one shorten the following using ternary operators?
if ((pos - maxPos) == (c.clientWidth)) {
$j("#next").addClass("filter");
} else {
$j("#next").removeClass("filter");
}
No need to use a ternary operator,
.toggleClass()
accepts a second argument to determine if the class should be added or removed:However, for the sake of answering your question exactly like you asked (don't use it!):
Even better than a ternary, using the
switch
param intoggleClass()