문제

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.

도움이 되었습니까?

해결책

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 
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top