How can I cancel the repeated call to $ (document) .on?

  • 0
    So the story is like this:
    My pages are loaded with ajax. Javascript and css are loaded along with the page.
    That is, when the user clicks & lt; a & gt; with href = / filter, then not the entire page is updated, but only the content of the page with scripts that apply only to this page is loaded.

    But! I have events written in javascript like this:
    $ (document) .on ('click', '. buttons', function () {});

    It turns out that if the user clicks on the / filter link again, the html-code is updated, the script is loaded again, another handler is created, and now if you click on .buttons, the event is triggered twice.

    Is there some way to remove all .on handlers loaded into memory?

    I must say right away that .off () is not what you need. it removes an event from a specific element, although the event on the system remains running.
    JavaScript Anonymous, Apr 5, 2019

  • 0 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!