Help with Auto-closeable alert box

Hi,

I’m practically brushing off my JS skills as a developer, I have this message alert-box, and I know how to close it using Javascript, what I want to automatically configure without clicking a button is for the error(alert) box to slideup automatically after
displaying the error. How do I effect that.

$(function () {
        $('.page-alert .close').click(function (e) {
            e.preventDefault();
            $(this).closest('.page-alert').slideUp();
        });   //This is for closing the box manually

I need the help with the one that closes automatically after a delay-- I have something am working on

$('.page-alert').on('active',function(e) {
        e.preventDefault();
        var id = $(this).attr('data-toggle-id');
        var alert = $('#alert-' + id);
        var timeOut;
        alert.appendTo('.page-alerts');
        alert.slideDown();
        
        //Is autoclosing alert
        var delay = $(this).attr('data-delay');
        if(delay != undefined)
        {
            delay = parseInt(delay);
            clearTimeout(timeOut);
            timeOut = window.setTimeout(function() {
                   $(this).closest('.page-alert').slideUp();
                }, delay);
        }
    }); //I know this is where the error is..
 

Hi,

Try updating this part of code:

 alert.slideDown();
        
        //Is autoclosing alert
        var delay = $(this).attr('data-delay');
        if(delay != undefined)
        {
            delay = parseInt(delay);
            clearTimeout(timeOut);
            timeOut = window.setTimeout(function() { alert.slideUp(); }, delay);
        }
    }); 

if that not works, can u post what error js is throwing?

Leave a Reply