Nodejs HTML Element Class Add addClass(className)

Here you can find the source of addClass(className)

Method Source Code

Element.prototype.addClass=function(className){
   var classNames=this.className.split(' ');

   // first check if Element has className
   for(var i=0;i<classNames.length;i++){
      if(classNames[i]===className){
         // nothing to do
         return true;
      }/* w w w. j a  v  a 2  s. c o m*/
   }

   // add className now
   this.className+=' '+className;
   return true;
};

Related

  1. addClass(className)
    Element.prototype.addClass = function(className) {
      const currentClasses = this.className
      this.className = `${currentClasses} ${className}`.trim()
      return this
    
  2. addClass(className)
    Element.prototype.addClass = function(className){
      var existing = this.className.length, spacer = "";
      if(existing > 0) spacer = " "; 
      if (!this.hasClass(className)) this.className = (this.className + spacer + className);
      return this;
    
  3. addClass(cls)
    Element.prototype.addClass = function(cls) {
      if (!this.hasClass(cls)) { this.className += " " + cls; }
    };
    
  4. pushClass(className)
    Element.prototype.pushClass = function(className){
      this.className += ' ' +className
    
  5. styles(css)
    HTMLElement.prototype.styles = function (css) {
        for (var property in this.style) {
            if (css[property]) this.style[property] = css[property];