Posted By

BuschFunker on 02/18/14


Tagged


Versions (?)

Function changeClass(element, action, class)


 / Published in: JavaScript
 

changeClass() as combination of element.classList.[action] and jQuery.[action]Class()

  1. var changeClass = function(element, action, class) {
  2. if(element) {
  3. var action = action || 'toggle',
  4. class = class || '';
  5.  
  6. if(element.classList) {
  7. element.classList[action](class);
  8. } else {
  9. $(element)[action+'Class'](class);
  10. }
  11.  
  12. return element;
  13. } else {
  14. return false;
  15. }
  16. }

Report this snippet  

You need to login to post a comment.