0

What is the equivalent of this javascript addEventListener

function displayStorageEvent(e) {
    if (e.key == 'storage-event') {
        output.innerHTML = localStorage.getItem("storage-event");
    }
}
window.addEventListener("storage", displayStorageEvent, true);

to Jquery? I have been trying to use it with .bind() but it does not know the "storage" keyword. I tried it with this but 'e' is undefined.

$(document).ready(function(){
    displayStorageEvent();
});

thanks.

leeshin
  • 1,043
  • 5
  • 15
  • 30

1 Answers1

0

I think I got it. I did not realize that I overlooked a few information.

$(document).ready(function(){
    $("#mybutton").bind("click", function(){
        updateStorageEvent();
        $("#mydiv").html(localStorage.getItem("storage-event"));
    });

    $(window).bind("storage",function(e){
        $("#mydiv").html(localStorage.getItem("storage-event"));
    });

});
leeshin
  • 1,043
  • 5
  • 15
  • 30