Dom Element onclick (MooTools :: optionally)

Posted by Theofanis Pantelides on Stack Overflow See other posts from Stack Overflow or by Theofanis Pantelides
Published on 2010-06-17T07:50:38Z Indexed on 2010/06/17 7:53 UTC
Read the original article Hit count: 202

Consider the following example:

function async_callback(array1, array2, array3) {
  // All arrays are equal length

  for(var i = 0; i < array1.length; i++) {
    var myElement = new Element('div', { 'id': 'dvMy' + i, 'events': { 'click': function() { SomeFunction(array1[i], array2[i], array3[i] } }});
    $(document).appendChild(myElement);
  }
}

Now when I click my element, I get a null value for all three arguments. I even tried doing: myElement.onclick = SomeFunction; // but this won't allow arguments I know I can create a string and use eval() and that does work, but I don't like eval().

Any ideas???

btw: This is a simple example to replicate the problem, and not actual code.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about events