Nodejs Utililty Methods HTML Element Class Add

List of utility methods to do HTML Element Class Add

Description

The list of methods to do HTML Element Class Add are organized into topic(s).

Method

addClass(className)
Element.prototype.addClass = function(className) {
  const currentClasses = this.className
  this.className = `${currentClasses} ${className}`.trim()
  return this
addClass(className)
Element.prototype.addClass=function(className){
  var classNames=this.className.split(' ');
  for(var i=0;i<classNames.length;i++){
    if(classNames[i]===className){
      return true;
  this.className+=' '+className;
  return true;
...
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;
addClass(cls)
Element.prototype.addClass = function(cls) {
  if (!this.hasClass(cls)) { this.className += " " + cls; }
};
pushClass(className)
Element.prototype.pushClass = function(className){
  this.className += ' ' +className
styles(css)
HTMLElement.prototype.styles = function (css) {
    for (var property in this.style) {
        if (css[property]) this.style[property] = css[property];
addStyleClass(className)
Element.prototype.addStyleClass = function(className) {
    if (className && !this.hasStyleClass(className))
        this.className += (this.className.length ? " " + className : className);
};