Jpietrangelo,
I'm afraid that [ICODE]element.setAttribute('onclick','...');[/ICODE] won't work.
Whereas HTML makes "onclick" look like an attribute, it is in fact an event.
In javascript, event handlers need to be attached with [ICODE]element.onclick = fn;[/ICODE], where fn is either the name of a function defined elsewhere (in scope) or an anonymous function … Read More

Whereas HTML makes "onclick" look like an attribute, it is in fact an event.

In javascript, event handlers need to be attached with element.onclick = fn; , where fn is either the name of a function defined elsewhere (in scope) or an anonymous function defined at this point in the code (as per my post above).

For completeness, you can also make a function call element.onclick = fn(data); providing fn returns a function. This is a very useful pattern, which creates a "closure" containing data , which remains available to the returned function even after fn has completed and returned!

Actually, it works fine. However, I understand what you are saying and thank you for the clarification.

Jim

Jpietrangelo,

I'm afraid that element.setAttribute('onclick','...'); won't work.

Whereas HTML makes "onclick" look like an attribute, it is in fact an event.

In javascript, event handlers need to be attached with element.onclick = fn; , where fn is either the name of a function defined elsewhere (in scope) or an anonymous function defined at this point in the code (as per my post above).

For completeness, you can also make a function call element.onclick = fn(data); providing fn returns a function. This is a very useful pattern, which creates a "closure" containing data , which remains available to the returned function even after fn has completed and returned!

Reading here we learn that the HTML 4.0 inteface is now a legacy thing superceded by the "DOM Event Model", under which "event listeners are no longer stored as attribute values", whilst still supporting HTML 4.0 event listeners.

MS never implemented a javascript interface in IE to mimic HTML 4.0 event listeners, whilst Moz/derivitives, from what you say, clearly did (and still do!).

I just tried your code in FF and you're quite right - it works - but not in IE.

It's OK, IE can handle this without jQuery as per my first post in this topic. But it can't perform .setAttibute('onclick', 'js_string') , which was a proprietary Moz thing never implemented by MS and not adopted by W3C in favour of the DOM Event Listeners approach and element.onclick= , which are now universal (at least as universal as things get in this funny world).