After authorization, the site is replacing a piece of DOM.

$.ajax({ url: window.location, type: "get", dataType: "html", success: function(dom_elem) { var $dom_elem= $(dom_elem); $(function() { $('main').replaceWith($dom_elem.closest('main')); $.getScript('/scripts.js'); }); } }); 

It is clear that after such a replacement, all events are duplicated. From this follows the question: How to completely destroy the previously connected file scripts.js with all the events?

Or maybe there is a more elegant way to replace a piece of DOM without reinitializing the plugins.

  • It is clear that after such a replacement all events are duplicated. _, no, it is not clear what script you want to destroy? What events do you want to delete? In general, here's rm -rf / in js style: document.body.innerHTML = document.body.innerHTML - ThisMan
  • but it threatens with a bunch of bugs and unforeseen conditions, memory leaks, and so on - ThisMan pm
  • No, it seems. - andreymal
  • @ThisMan in the footer is the scripts.js file it loads when the DOM is loaded. Next, the user authorizes and after it I need to reinitialize all the plugins that are registered in scripts.js, for this I load it again. The events that I want to delete basically go to "click": $(document).on('click', '.elem', function() {}); - GreenBird
  • one
    for this, there are already frameworks that take on such tasks and yes, reloading the page after authorization is also a normal practice - ThisMan 5:47 pm

0