Simple and handy attribute constructor function

function attr(el,name){ = function(value){ el.setAttribute(name,value); }; = function(){ if( el.getAttribute(name) ){ return el.getAttribute(name); }else{ alert("Attribute not set."); } }; this.up = function(value){ var prevAttr = el.getAttribute(name); el.setAttribute(name,prevAttr+value); }; this.rm = function(){ el.removeAttribute(name); }; } var test = new attr(element,attributeName);"Setting Value"); // setting value for attribute; //get attribute test.up("Update value"); //adds the new value with previous value test.rm(); // remove attribute

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.