Reputation: 2333
I have this code:
$('.bird').each(function(){
$(this).load(function(){
if($(this).is(".bird:last")){
$('#floatingBarsG').remove();
$('#step0').fadeIn(600);}
});
})
Where I try to do some events if $(this)
is last element on the page with class .bird
, and this code doesn't work.
What is wrong?
Upvotes: 1
Views: 341
Reputation: 57095
$('.bird').click(function () {
if ($('.bird').length - 1 == $(this).index('.bird')) {
alert('last')
}
})
Upvotes: 1
Reputation: 388316
Try
var $birds = $('.bird').each(function () {
$(this).load(function () {
if ($birds.last().is(this)) {
$('#floatingBarsG').remove();
$('#step0').fadeIn(600);
}
});
})
Upvotes: 3