[thelist] onclick not working in IE6 or IE7 - script works in Firefox

Matt Warden mwarden at gmail.com
Wed May 14 00:50:21 CDT 2008


On Wed, May 14, 2008 at 1:02 AM, Blake <haswell00 at gmail.com> wrote:
>  for(var i = 0; i < link.length; i++) {
>         link[i].onclick = swapStories; // This has the problem that I can't
>  pass the argument through so it's useless for me
>
> }
>
>  for(var i = 0; i < link.length; i++) {
>         link[i].onclick = function() {
>                 swapStories(i); // This has the problem that the function isn't run
>  until the element is clicked, and since I'm passing a counter the
>  value is useless by the time the event triggers
>
>         }
>  }

The easiest way to do this is to assign that as an additional attribute:

for(var i = 0; i < link.length; i++) {
       link[i].loopCounter = i;
       link[i].onclick = swapStories;
}

Some may argue this is bad form, as it is not apparent from the code
that you are passing an argument to swapStories. However, depending on
what the counter value means, it may be valid to assign it as a
property. Your call.

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


This email proudly and graciously contributes to entropy.



More information about the thelist mailing list