
Added by thebman220 on October-12-2008, 9:20 pm
element.hasAttribute("tagName")
is false, because 'tagName' not an attribute. This function tests if an element object has a certain variable defined.
/**
* @param object elem : the DOM element to be tested
* @param string attr : the attribute to test for
* @return boolean : true if the attribute exists, false otherwise
*/
function elemHasAttribute(elem,attr) {
var isset;
try {
eval("isset=typeof elem."+attr+"!='undefined';");
} catch (e) {
isset=false;
}
return isset;
}
/**
* @param object elem : the DOM element to be used
* @param string attr : the attribute to get
* @return boolean : the value of the attribute or null on error
*/
function elemGetAttribute(elem,attr) {
try {
return eval("elem."+attr);
} catch (e) {
return null;
}
}
/**
* @param object elem : the DOM element to be used
* @param string attr : the attribute to set
* @param mixed val : the value to set to attr
* @return boolean : true on success or false on error
*/
function elemGetAttribute(elem,attr,val) {
try {
eval("elem."+attr+"=val;");
return true;
} catch (e) {
return false;
}
}
Added by thebman220 on October-14-2008, 4:36 pm
Added by thebman220 on October-13-2008, 5:01 pm
Added by thebman220 on October-13-2008, 12:13 am
Added by thebman220 on October-12-2008, 10:22 pm
Added by thebman220 on October-12-2008, 9:36 pm