Jacob Valenta
Jacob Valenta

Reputation: 6769

Quick and Dirty Notification JQuery

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

Answers (2)

Piet van Dongen
Piet van Dongen

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

j08691
j08691

Reputation: 208032

$('.notification').last();

Would select the last .notification element.

See http://api.jquery.com/last/

Upvotes: 0

Related Questions