jquery - Javascript hide DIV, Button clicked -
hi there stackers,
i'm problem. it's javascript (again). i've been creating "alerts" on webpage. contain button, , want close them when click on button. however, doesn't seem work. i've logged clicks in console, , click logged. click happen.
the alerts hide after few seconds. when change style "devtools" of chrome make visible again, , click button then, div dissapear.
why click not hide div?
javascript
var messageid = 0; var alerty = function(type, title, content) { messageid++; var html = ' <div class="alert" id="a-' + messageid + '"><div class="topview ' + type + '"></div><div class="title">' + title +'</div> <div class="text">' + content +'</div> <input type="button" id="close-'+ messageid + '" class="inputbutton-empty ' + type + '2 button close" value="meldung schließen"></div>' $(html).hide().appendto("#alertcontainer").fadein("fast"); $(".alert").delay(8000).fadeout(); $("#close-" + messageid ).click(function() { console.log("xtm: pushed alerty alert closed on request."); $("#a-" + messageid ).hide("fade", "fast"); }); }
thanks in advance, pascal
it delay()
preventing hide()
call. try clearing queue first in close function:
$("#close-" + messageid ).click(function() { console.log("xtm: pushed alerty alert closed on request."); $("#a-" + messageid ).stop().hide("fade", "fast"); });