0

I needed to add an onclick event in a loop, so I searched and came across this: Setting onclick to use current value of variable in loop The problem with it, however, is that it always returns a mouse event. I did pretty much the exact same thing except with my own function, but it just returns a mouse event. I have no clue why and it doesn't make any sense to me. Here's the code:

var a=m.getElementsByTagName('topic');
for(var b=0,c=a.length;b<c;b++) a[b].onclick=function(a) {
    return function(a) {
        goToMB(a);
        };
    }(a[b].getAttribute('topicid'));
Community
  • 1
  • 1
Ruffy
  • 835
  • 1
  • 10
  • 17

1 Answers1

0

Try this:

var a = m.getElementsByTagName('topic');
for(var b = 0, c = a.length; b < c; b++) {
    a[b].onclick = function(a) {
        return function() { goToMB(a); }
    }(a[b].getAttribute('topicid'));
}
Shef
  • 44,808
  • 15
  • 79
  • 90