开发者

how to get the value of multiple attr when clicked on

$(document).ready(function(){
    $('td#crop').click(function() {
        $('img').each(function(){
          $('this').attr(id);
         alert(id开发者_C百科);
        });

        })

});

I am trying to get the the value of the id of each image I click on but this is not working,Please help


this should not be a string, and you need to save the value returned by .attr().

$(document).ready(function() {
    $('#crop').click(function() {
        $('img').each(function() {
            var id = $(this).attr(id);
            alert(id);
        });
    });
});

Other cleanup:

  • Added a missing semicolon (though that wasn't enough to break the code).
  • Changed over-specifed selector 'td#crop' to '#crop', since there can be (at most) one element with a particular ID.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜