Created
July 2, 2016 21:26
-
-
Save andrejewski/e4279f5964d37fb1a1bbf7c0419501d6 to your computer and use it in GitHub Desktop.
more functional jQuery
This file contains 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
$.fn.extend({ | |
setClass: function(name, add) { | |
if(typeof name === 'object') { | |
const classes = name; | |
Object.keys(classes).forEach(className => { | |
this.setClass(className, classes[className]); | |
}); | |
} else { | |
this.each((index, elem) => { | |
if(add) { | |
$(elem).addClass(name); | |
} else { | |
$(elem).removeClass(name); | |
} | |
}); | |
} | |
return this; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment