0

I have a simple script that adds a click event listener to an element that is not currently on the screen. It works fine when I first visit a page but if I click a link to another page then come back it doesn't work, I don't get any errors in the console it just does nothing. Here is the script

$(function () {
    // event listener for removing overlay and form when clicking form close button
    addCloseButtonBehaviour();
});

function addCloseButtonBehaviour() {
    $('body').on('click', '#close-button', function () {
        $('#form-container').remove();
        $('#full-screen-overlay').remove();
    });
}

Can anyone tell me a way that I can do this and ensure that it works every time I visit the page? Thanks in advance everyone.

thedeliciousmuffin
  • 784
  • 1
  • 10
  • 22
antonyCas
  • 81
  • 2
  • 8

0 Answers0