jquery performance of binding multiple click events.

Posted by DA on Stack Overflow See other posts from Stack Overflow or by DA
Published on 2010-03-29T20:21:48Z Indexed on 2010/03/29 20:33 UTC
Read the original article Hit count: 332

Filed under:
|

I have a situation where I need to bind a click event to an object multiple times.

For instance:

for(i=0;i<=100;i++){
    $myObject.click(function(){
         window.location = "myurl"+i+".html";
    })
    ...do other stuff...
}

Via that markup, does $myObject end up with 100 click events attached to it? Should I be unbinding the click event first each time?

for(i=0;i<=100;i++){
    $myObject.unbind('click').click(function(){
         window.location = "myurl"+i+".html";
    })
    ...do other stuff...
}

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about event