Skip to content

Instantly share code, notes, and snippets.

@yarysh
Created June 5, 2013 11:10
Show Gist options
  • Select an option

  • Save yarysh/5713156 to your computer and use it in GitHub Desktop.

Select an option

Save yarysh/5713156 to your computer and use it in GitHub Desktop.
addClass function for JavaScript
function addClass(o, c){
var re = new RegExp("(^|\\s)" + c + "(\\s|$)", "g");
if (re.test(o.className)) return;
o.className = (o.className + " " + c).replace(/\s+/g, " ").replace(/(^ | $)/g, "");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment