Ok, took me a few times reading through your code to fully understand it, but I get it now. So basically, you create an exception list for attributes that are problematic or don't add the same in all browsers. If the attribute is in the exception list, it calls _set_node_prop( ), which uses the javascript node[attr] = value method. If the attrib is not in the exception list, it uses the DOM node.setAttribu te(attr, value) method. Makes sense now.
But why a separate function for exceptions rather than this:
[code=javascript]
function set_node_attr(d ocroot, id, attr_state, attr, value)
{
var node = docroot.getElem entById(id);
var exceptions =
{
onclick: 1
};
if (attr in exceptions)
{
node[attr] = value;
}
else if (attr_state)
{
node.setAttribu te(attr, value);
}
else
{
node.removeAttr ibute(attr);
};
};
[/code]
And how would you remove a attr in the exceptions list? Set value to null?
As for using attachEvent(), I think your example here helped me understand better the addEvent() code I posted (obviously, I didn't write it). I could, for instance, do this:
[code=javascript]
addEvent(docume nt.getElementBy Id('image"), "click", someFunction);
[/code]
But why a separate function for exceptions rather than this:
[code=javascript]
function set_node_attr(d ocroot, id, attr_state, attr, value)
{
var node = docroot.getElem entById(id);
var exceptions =
{
onclick: 1
};
if (attr in exceptions)
{
node[attr] = value;
}
else if (attr_state)
{
node.setAttribu te(attr, value);
}
else
{
node.removeAttr ibute(attr);
};
};
[/code]
And how would you remove a attr in the exceptions list? Set value to null?
As for using attachEvent(), I think your example here helped me understand better the addEvent() code I posted (obviously, I didn't write it). I could, for instance, do this:
[code=javascript]
addEvent(docume nt.getElementBy Id('image"), "click", someFunction);
[/code]
Comment