Hide dismissed notifications with jQuery and cookies

5 Nov 2013

It’s quite easy to write a jQuery or plain JS script that dismisses an alert message but sometimes you want a little bit more. Usually that is to keep that notification hidden when you refresh the page. that can be done using various approaches and one of them is to use cookies. It’s as simple as setting/updating a cookie that contains a string with the ids of the notification containers that were dismissed.

Here’s an example of the html and JS.

This uses jQuery but can be easily rewritten to have no dependencies.
If you have a better way of doing this, or any comments, please let me know!

A demo can be seen on CodePen.

Get better with Javascript and JQuery:

Here are some books that will help you get better at Javascript and Jquery