I’ve got a link intended to dismiss a notification banner. Currently, the only way I know how to handle this is by reloading the page to both make the change in the database and to make the banner disappear. I know this can be done without reloading the page but I am having a problem figuring out how to do it. I tried to integrate this tutorial but on clicking dismiss, it loads the page and the banner persists.
Oh that’s leftover from the tutorial, I accidentally failed to convert it.
I made the fix and now the script is working but instead of removing the notification div(which was my intention), it’s only revmoving the text and button from inside it. How would I modify it to remove the entire notification div? (I added a notification_dismissed ID to it).
I’ve updated the code to reflect latest changes up top.
Just remove() it then instead of clearing its inner HTML. BTW, instead of collecting the form input values manually you can just serialize() the entire form, or create a FormData object like so:
You might have a look at the slideUp() and fadeOut() methods… although jQuery animations are terribly bad for performance.
So yes I’d rather do this with CSS, or a combination of CSS and JS. For example, you can use CSS for the actual animation and let the browser do the “heavy lifting”, and then only use JS to remove the element once the animation is finished: