Close a notification using custom buttons
Notifications onweb can be closed by clicking on the (x) button by default.
In some cases, one would like to create a custom button that closes the Notification instead of the default (x) button.
You can do so by adding a click event listener to the selector of the custom element. Once the element is clicked, you can trigger a click on ".dy-lb-close", which is the (x) selector.
Using jQuery as an example:
$('CUSTOM_CLOSING_BUTTON_SELECTOR').onClick(){
$('.dy-lb-close').click();
}
Otherwise, you can hide notification by adding the CSS rule "display: none" to the parent element using JavaScript, or by using the corresponding jQuery method .hide().
$('CUSTOM_CLOSING_BUTTON_SELECTOR').onClick(){
$('NOTIF_PARENT_SELECTOR').hide();
}
Another jQuery option is to use .remove() instead of .hide().
jQuery is a library that may not be available on your website. In this case, basic JavaScript methods can be used instead.
Please sign in to leave a comment.
Comments
0 comments