Nodejs HTML Element Toggle toggleAttribute(name, value = "")

Here you can find the source of toggleAttribute(name, value = "")

Method Source Code

/**/*from www .  j av  a 2  s. c  o m*/
 * Uppercase first letter
 * @returns
 */

Element.prototype.toggleAttribute = function(name, value = "") {
   if ( this.hasAttribute(name) ) {
      this.removeAttribute(name);
   }
   else {
      this.setAttribute(name, value);
   }
}
String.prototype.ucFirst = function() {
   return this.charAt(0).toUpperCase()+this.slice(1);
}

Related

  1. toggleDisplay()
    Element.prototype.toggleDisplay = function() {
      if (this.style.display != "")
        this.style.display = "";
      else
        this.style.display = "none";
    
  2. toggle()
    HTMLElement.prototype.toggle = function toggle() {
        this.style.visibility = (this.style.visibility === "hidden") ? "visible" : "hidden";
    };