Michael Chase’s Weblog

November 16, 2010

Javascript Gems: Dynamically change element’s onclick event

Filed under: Javascript — mbrazell @ 9:19 pm

var input = document.createElement(“input”);

input.onclick = someFunction; // not someFunction(); or “someFunction()”;

- OR -

input.onclick = function() { };

It must be a pointer to the function, not a function call or string.  Also note that the event is named “onclick”, not “onClick”.

Advertisement

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.