Why does it break when wrapping the code in $ (document) .on ('click', function ({});?

  • 0
    When you click on a letter, it is added to the text field, but when I wrapped the code in this construction, then with each subsequent click, the number of letters being entered increases. Easier to see with an example:
    How to fix it?
    Such a wrapper is needed for the code to work in a block that is loaded with ajax.

    P.s. The answer fallus in the comments is what you need. Thank you
    JavaScript Anonymous, Oct 23, 2020

  • 2 Answers
  • 0
    every time at document.onclick this is all called, and new event listeners are added to the spans

    This wrapper is needed for ajax


  • 0
    I didn't understand anything (including what the mix from native js and jquery is for).

    But it's easier to figure it out:

    But again, I didn't understand anything.

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