[thelist] Javascript onclick doesn't fire?

Matt Warden mwarden at gmail.com
Tue Aug 22 14:27:31 CDT 2006


Hi Stephen,

On 8/22/06, Stephen Rider <evolt_org at striderweb.com> wrote:
> Does anyone have any idea what might be happening here?  Does IE
> ignore onclicks that are themselves written by javascript?
>
> Here is one of the pages in question:
> <http://tinyurl.com/rtryv>

It looks like you are using setAttribute(). First, this is sort of
missing the point. Second, it won't work.

It's missing the point, because you're trying to attach a JavaScript
property, not a HTML attribute. The fact that you *can* assign a JS
property using a HTML attribute is, I believe, confusing you. But,
you're trying to avoid mixing markup and behavior, thus you do not
want to use this method.

Second, it won't work, because IE doesn't like you using setAttribute
for things where you have direct access to the JS property.

You want to do something like this:

arrPicLink[i].onclick = new Function(firstPart + (i+1) + thirdPart);

Really, though, we're moving away from .onclick. Take a look at this function:

http://mwarden.f2o.org/sandbox/viewsource.php?linemode=0&f=eventlistener2.js

or, even better, use YUI:

http://developer.yahoo.com/yui/docs/event/YAHOO.util.Event.html#addListener

-- 
Matt Warden
Cleveland, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.



More information about the thelist mailing list