remove an element from the DOM and do not load it again when refreshing the page

0

I am removing a div with remove() , but I need to delete it completely, I explain to delete it with remove it removes it but if I update the browser or refresh the page it shows again I need to delete it and no longer load if the page is refreshed , I do not know if it can be stored in a variable value, or using cokies I'm not sure, thanks for the help.

$('.midiv').remove();
    
asked by Sixto Mujica 04.04.2018 в 16:55
source

1 answer

2

I really do not understand why you want to do it, but as you say you can do it by storing a variable that lasts even if you reload the page, so use localStorage or sessionStorage of the following form

$( document ).ready(() => {
    let quitarDiv = sessionStorage.getItem('quitarDiv');
    if (quitarDiv !== true) { // puede devolver undefined si no esta seteada
      $(".midiv").remove();
    }
});


function onQuitarDiv() {
  sessionStorage.setItem('quitarDiv', true);
  $(".midiv").remove()
}

I can not give you a practical example because the stackoverflow sandobox does not let you work with any of the two.

    
answered by 04.04.2018 в 17:18