jquery: get value from clicked div

前端 未结 2 968
太阳男子
太阳男子 2021-02-06 08:33
\'.$i.\'

$i is auto generated by loop - which could lead to:

\'.$i.\'
\'.$i.\
2条回答
  •  野的像风
    2021-02-06 09:16

    $('div').click(function(event){
      alert($(this).text());
    });
    

    A more efficient solution (since it seems you have a lot of

    s would be to add a live event to the wrapping element of those, like this:

    $('#container').live('click', function(event){
       if(event.target.tagName == "DIV") alert($(event.target).text());
    });
    

提交回复
热议问题