Posted By

marcio on 02/15/08


Tagged

javascript class toggle


Versions (?)

toogle class


 / Published in: JavaScript
 

  1. function toggleClassName(el, name) {
  2. var deleted = false;
  3. var aClasses = el.className.split(' ');
  4. for (var i = 0; !deleted && i < aClasses.length; ++i) {
  5. if (aClasses[i] == name) {
  6. delete(aClasses[i]);
  7. deleted = true;
  8. }
  9. }
  10. if (!deleted) aClasses[aClasses.length] = name;
  11. el.className = aClasses.join(' ');
  12. }

Report this snippet  

You need to login to post a comment.