alert = function(what){ // if the element hasn't been appended to the body element if($("#alert_bar").length==0){ // customize the bar with css var bar = $("<div/>").css({ 'display':'none', 'position':'fixed', 'top':'0px', 'left':'0px', 'zIndex':'99950', 'width':'100%', 'margin':'0px', 'padding':'5px auto 9px auto', 'textAlign':'center', 'fontSize':'16px', 'background':'#fff', 'color':'red', 'borderBottom':'solid 1px #333' }) bar.attr("id","alert_bar") $('body').prepend(bar) } // close button $("#alert_bar").html('<div style="text-align:right;font-size:10px;color:red"><span style="cursor:pointer" onclick="$(\'#alert_bar\').slideUp()"></span></div><div>'+what+'</div>') $("#alert_bar").slideDown(); auto = 2000; window.setTimeout(function(){ $("#alert_bar").slideUp() },auto); }