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.
精彩评论