开发者

how to get the value of multiple attr when clicked on

开发者 https://www.devze.com 2023-02-20 05:11 出处:网络
$(document).ready(function(){ $(\'td#crop\').click(function() { $(\'img\').each(function(){ $(\'this\').attr(id);
$(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

精彩评论

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