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

Peter-Paul Koch gassinaumasis at hotmail.com
Wed Mar 19 09:29:10 CST 2003



> >>                          // 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.

True, but in practice I found that many problems can be avoided by avoiding 
set/getAttribute when possible. It's about the only more or less general 
rule I found for using the W3C DOM, so I repeat it whenever I have the 
chance.

>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.

Well well, interesting. I didn't know that.

>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).

I hadn't thought of that.

>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.

<plug type="shameless">

On my W3C DOM mailing list (http://www.xs4all.nl/~ppk/js/list.html) we often 
discuss problems like this one. Event handler registration, especially, 
turns out to be a rather problematical area with many small browser 
problems.

If you're interested in getting the DOM to work in all browsers you might 
consider joining the list, as many JavaScript developers have done before 
you.

</plug>

--------------------------------------------------
ppk, freelance web developer
Interaction, copywriting, JavaScript, integration
http://www.xs4all.nl/~ppk/
Column "Keep it Simple": http://www.digital-web.com/columns/keepitsimple/
W3C DOM Compatibility Table, expanded & updated
http://www.xs4all.nl/~ppk/js/index.html?version5.html
--------------------------------------------------


_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. 
http://join.msn.com/?page=features/virus



More information about the thelist mailing list