简体   繁体   中英

Close button for Jquery notification bar

On this page " jquery notification bars that can be dismissed? " I found a nice and clean jquery notification bar. Fiddle here: Demo .

To close the bar, you just click anywhere in its body. How can I change this behavior? I need to add a close button (an X), that when clicked closes the bar. If the user clicks in the notification bar body, the desired result is that nothing should happen.

This is the code that closes the bar:

$('#notify').click(function() {
    $(this).slideUp().empty();
});

Thank you!

You could do something like this:

HTML

<div id="notify">Welcome to the test page!<span id="closeNotify"> X </span></div>

Javascript

$('#closeNotify').click(function() {
    $('#notify').slideUp().empty();
});

$(function(){
    $('#notify').slideDown();
});

JSFiddle

Well, just do:

$('#close-btn').click(function() {
    $('#notify').slideUp().empty();
});

Where #close-btn is, as you would have guessed, the button that closes the notify bar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM