[thelist] adding an event to a DOM dynamically added row

Danny Goodman dannyg at dannyg.com
Wed Mar 19 09:00:49 CST 2003


on 3/19/03 4:02 AM, thelist-request at lists.css-discuss.org wrote:

>> I am adding rows to a table with the DOM. They now want to
>> add an onclick event as well. They were trying setAttribute()
>> with no success. Anyone know how we could accomplish this?


The following message got lost in the evolt transition, so here's a re-send:


>>                          // we want an onclick on this button for
>> example
> 
> field.onclick = functionName;
> 
> Don't use setAttribute and getAttribute, except when there is no other way
> to do what you want to do.

I wouldn't go that far, since the W3C DOM prescribes
setAttribute()/getAttribute() as the way to write/read attribute values.

That said, setAttribute() doesn't work for event handlers in IE (Win/Mac).
For some reason IE doesn't resolve the value to the function object, so
nothing happens at event time. It does work in Mozilla, however, and can be
beneficial in some cases: creating an event handler call that passes
arguments consisting of values assembled in the script setting the attribute
(rather than relying on the event object's properties for details). In any
case, to assign (or reassign) an event handler on the fly, event handler
property assignment, as shown above, is the way to go if you need to serve
IE in your audience browser mix.

Danny
http://www.dannyg.com



More information about the thelist mailing list