it's not possible to loop .click function (To create multipple buttons)

Posted by user1542680 on Stack Overflow See other posts from Stack Overflow or by user1542680
Published on 2012-10-17T16:55:06Z Indexed on 2012/10/17 17:00 UTC
Read the original article Hit count: 142

Filed under:
|
|

Im Trying to create multiple buttons that each one of them doing something else. It working great outside of the "each" loop, But in the moment I'm inserting the .click function in the .each function it doesn't work...

Here is the Code:

$.each(data.arr, function(i, s){
    html += '<div id="mybtn'+s.id+'"><button class="first">Btn1</button><button class="second">Btn2</button></div>';

    var btnclass="#mybtn"+s.id+" .first";

    $(btnclass).click(function(){
      //do something 
    });
});

Please Let me know what is wrong...

Thank you very much!!!

Eran.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX