Skip to content

Instantly share code, notes, and snippets.

@blackmiaool
Last active July 19, 2017 09:57
Show Gist options
  • Select an option

  • Save blackmiaool/49378c41c18e1a4998ae21bdfdb0fd51 to your computer and use it in GitHub Desktop.

Select an option

Save blackmiaool/49378c41c18e1a4998ae21bdfdb0fd51 to your computer and use it in GitHub Desktop.
toggle class
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;
}
@blackmiaool
Copy link
Copy Markdown
Author

test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment