2012-07-10 53 views
1

我有以下設置的onclick刪除:jQuery的 - 從一個元素

<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> 

現在我需要做的是在某一時刻刪除所有的onclick事件。我試過$(「#whatever」)。unblind('click');但是這隻消除了使用jquery添加的事件,dostuff()函數仍然被調用。

任何想法我怎麼能一次刪除所有?

P.S.不要開始問爲什麼some1有內聯onclick和聽衆。

回答

11

可以使用removeAttr()方法:

在匹配的元素取下每個元素的屬性。

$('#whatever').removeAttr('onclick') 
$("#whatever").click(function() { 
    //do something 
});