How to disable and then enable onclick event on <div> with javascript [closed]
Following is the code which i am trying
document.getElementById("id").disabled = true;
Solution 1:
You can use the CSS property pointer-events
to disable the click event on any element:
https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events
// To disable:
document.getElementById('id').style.pointerEvents = 'none';
// To re-enable:
document.getElementById('id').style.pointerEvents = 'auto';
// Use '' if you want to allow CSS rules to set the value
Here is a JsBin: http://jsbin.com/oyAhuRI/1/edit
Solution 2:
I'm confused by your question, seems to me that the question title and body are asking different things. If you want to disable/enable a click event on a div simply do:
$("#id").on('click', function(){ //enables click event
//do your thing here
});
$("#id").off('click'); //disables click event
If you want to disable a div, use the following code:
$("#id").attr('disabled','disabled');
Hope this helps.
edit: oops, didn't see the other bind/unbind answer. Sorry. Those methods are also correct, though they've been deprecated in jQuery 1.7, and replaced by on()/off()