How to temporarily disable a click handler in jQuery?

前端 未结 12 2025
不思量自难忘°
不思量自难忘° 2020-12-04 14:02

Say I have something like the following to trap the click event of a button:

$(\"#button_id\").click(function() {
  //disable click event
  //do something
           


        
12条回答
  •  生来不讨喜
    2020-12-04 14:48

    I noticed this post was old but it appears top on google and this kind of solution was never offered so I decided to post it anyway.

    You can just disable cursor-events and enable them again later via css. It is supported on all major browsers and may prove useful in some situations.

    $("#button_id").click(function() {
    
       $("#button_id").css("pointer-events", "none");
       //do something
       $("#button_id").css("pointer-events", "auto");
    }
    

提交回复
热议问题