Created
August 18, 2016 02:25
-
-
Save daniellealexis/2ecefe9e1366b9cfc839c5c4f646210d to your computer and use it in GitHub Desktop.
jQuery's toggleClass Function's Second Argument
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 5 lines?! Ugh | |
if( isTheThing ) { | |
$element.addClass('new-class'); | |
} else { | |
$element.removeClass('new-class'); | |
} | |
// At least it's one line now.. | |
( isTheThing ) ? $element.addClass('new-class') : $element.removeClass('new-class'); | |
// Sweet, sweet brevity! | |
$element.toggleClass('new-class', isTheThing); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment