[thelist] unobtrusive onclick without set attribute?

Matt Warden mwarden at gmail.com
Tue Jul 17 16:54:13 CDT 2007

On 7/17/07, Jon Hughes <hughesj at firemtn.com> wrote:
> Normally, I would simply use:
> Obj.property = "value";
> But
> Obj.onclick = "alert('hello world');";
> Does not do anything, while
> Obj.title = "New Title";
> Sets the title of obj to "New Title"
> So the question is, without using the buggy/unsupported "setAttribute" -
> How do I add this onclick?

You're half way there. It's not an attribute. It is a property with a
value that is a function reference. Thus:

Obj.onclick = function() {alert('hello world');};

Think of it this way: the event will call Obj.onclick(). So onclick
needs to refer to a function.

Matt Warden
Cincinnati, OH, USA

This email proudly and graciously contributes to entropy.

More information about the thelist mailing list