Created
July 5, 2016 23:42
-
-
Save mfurlend/abab788f92fc7a6adda855b9604aba23 to your computer and use it in GitHub Desktop.
Swap the two classes in the selector
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
$.fn.swapClass = function(a, b) { | |
if (a && b) { | |
this.toggleClass(a).toggleClass(b); | |
} else { | |
let arr = this.selector.split(','); | |
if (arr.length < 2) { | |
return this; | |
} | |
return this.swapClass(arr[0].substr(1), arr[1].substr(1)); | |
} | |
} | |
//usage: $('.class-A,.class-B').swapClass() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment