Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

254
Views
How can I remove every listener from a page?

I know how to remove a listener from an element, but how can I remove every event listener from every element on the page?

A jQuery and pure JS solution would be nice.

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

I would suggest to look into the .off function of jQuery. Also, based on this stackoverflow question, I would try to remove all every listeners with the following code

$("body").find("*").off();

Hope this could help you.

about 4 years ago · Santiago Trujillo Report

0

You can try this too.

http://jsfiddle.net/LkfLezgd/9/

$("#cloneButton").click(function() {
$('body').replaceWith($('body').clone().html());
});
about 4 years ago · Santiago Trujillo Report

0

You can loop through the form elements as below to remove the event listeners at your preferred way.

The fastest way to do this is to just clone the node which will remove all event listeners but this won't remove if 'onclick' attribute is used.

document.getElementById('button').addEventListener('click', onClick, false);

function onClick() {
   console.log('Form clicked');
   var form = document.getElementById('myForm');

   for(var i = 0; i < form.elements.length; i++){
       var elm = form.elements[i];
       removeEvents(elm);
   }
}

function removeEvents(elm) {
  // The fastest way to do this is to just clone the node, which will remove all event listeners:

   var new_element = elm.cloneNode(true);
   elm.parentNode.replaceChild(new_element, elm);
}
<form id="myForm">
   <input id="button" type="button" value="Click" />
</form>

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!