function attr(el,name){
this.st = function(value){
el.setAttribute(name,value);
};
this.gt = 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);
test.st("Setting Value"); // setting value for attribute
test.gt(); //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.