kamaci kamaci - 6 months ago 32
jQuery Question

Call a function after a certain time Jquery?

I am examining a js file form Bram Jetten:

Notification.fn = Notification.prototype;

function Notification(value, type, tag) {
this.log(value, type);
this.element = $('<li><span class="image '+ type +'"></span>' + value + '</li>');
if(typeof tag !== "undefined") {
$(this.element).append('<span class="tag">' + tag + '</span>');

* Show notification
Notification.fn.show = function() {

* Hide notification
Notification.fn.hide = function() {
$(this).animate({opacity: .01}, 200, function() {
$(this).slideUp(200, function() {


I assigned a click event one of my buttons and when I click that button it calls a new notification:

new Notification('Hi', 'success');

When I click that notification it closes as well. However if I dont click it after a certain time I want it close by itself. How can I call that hide function or close it after some time later when it appeared?

Answer Source
var that = this;

setTimeout(function() {   //calls click event after a certain time
}, 10000);

that worked for me.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download