/ Published in: JavaScript

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function cssRegex(c) { return new RegExp('(?:\\s|^)' + c + '(?:\\s|$)'); } function hasClass(e,c) { return e.className.match(cssRegex(c)); } function addClass(e,c) { if (!hasClass(e,c)) { e.className += ' '+c; return true; } return false; } function removeClass(e,c) { if (hasClass(e,c)) { e.className=e.className.replace(cssRegex(c),' '); return true; } return false; }
Comments
