Last active
July 19, 2017 09:57
-
-
Save blackmiaool/49378c41c18e1a4998ae21bdfdb0fd51 to your computer and use it in GitHub Desktop.
toggle class
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
| function toggleClass(allClass,className){ | |
| let got=false; | |
| allClass=allClass.replace(new RegExp(`(\\s|^)(${className})(\\s|$)`),function(full,pre,target,after){ | |
| got=true; | |
| //center | |
| if(pre&&after){ | |
| return " "; | |
| }else{ | |
| return "" | |
| } | |
| }); | |
| if(!got){ | |
| allClass+=` ${className}`; | |
| } | |
| return allClass; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
test