Question

I have the following setup:

   <div id="whatever" onclick="dostuff()">Super Mega Giga Button or Whatever</div>

   <!-- Import jquery and whatever other libs I need-->

   <script>
        $("#whatever").click(function() { //do something });
   </script>

Now what I need to do is at some point to remove all the onclick events.

I tried $("#whatever").unblind('click'); but this removes only the event added with jquery, the dostuff() function is still called.

Any idea how can I remove all at once?

P.S. Don't start asking why would some1 have inline onclick and also listeners.

Was it helpful?

Solution

You can use the removeAttr() method:

Remove an attribute from each element in the set of matched elements.

$('#whatever').removeAttr('onclick')
$("#whatever").click(function() { 
  //do something 
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top