Reputation: 6769
I have a notification function that just adds a <div class="notification"></div>
to #notification-area
.
I need to have the notification fade out after 5 seconds of a single notification being there. I could do it if I had access to the div I just added.
possibly $('.notification:last-child')
to select it?
Upvotes: 0
Views: 144
Reputation: 1639
You can do this:
var notification = $('<div class="notification"></div>');
$('#notification-area').append(notification);
setTimeout(function(){
notification.fadeOut();
notification.remove();
},5000);
Upvotes: 1
Reputation: 208032
$('.notification').last();
Would select the last .notification
element.
See http://api.jquery.com/last/
Upvotes: 0