HTML DOM Attributes Thursday, May 11, 2006

Ok, to start with this post is just dumb but, I just wanted to add a snippet.
This reference brought up an issue I had dealt with before when creating DOM nodes in IE.
Trying to set the css class with node.setAttribute("class",className); basically does nothing while working on every other browser.
The Chris' solution is to use a loop to find the attribute node and set the value. I think mine might be a bit less complex:

function setAttribute(node,name,value){
var att = node.getAttributeNode(name);
if(att){
att.value = value;
}else{
node.setAttribute(name,value);
}
}


Update, an even easier way to set the css class:

function setCssClass(node,className){
node.setAttribute("class",className,0);
node.setAttribute("className",className,0);
}

was posted by Chris Gillis


<willCode4Beer/> posted at 11:53 AM

0 Comments:

Post a Comment

<<< This way to the egress