$(function() { $('.modal-auto-clear').on('shown.bs.modal', function () { // if data-timer attribute is set use that, otherwise use default (7000) var timer = $(this).data('timer') ? $(this).data('timer') : 7000; $(this).delay(timer).fadeOut(200, function () { $(this).modal('hide'); }); }); })