Element toggle class - Node.js CSS

Node.js examples for CSS:Class

Description

Element toggle class

Demo Code

Element.prototype.toggleClass = function(tag) {
  var ret = false
  var classes = this.className.split(" ")
  var index = classes.indexOf(tag)
  if (index >= 0) classes.splice(index,1)
  else {//from   w ww .j a va 2s .  c  o  m
    classes.push(tag)
    ret = true
  }
  this.className = classes.join(" ")
  return ret
}

Related Tutorials