Following is the code which i am trying
document.getElementById("id").disabled = true;
We can bind a JavaScript function to a div using the onclick event handler in the HTML or attaching the event handler in JavaScript. Let us refer to the following code in which we attach the event handler to a div element. The div element does not accept any click events by default.
If you want to disable all the div's controls, you can try adding a transparent div on the div to disable, you gonna make it unclickable, also use fadeTo to create a disable appearance. try this. This doesn't prevent the user going to the links or inputs with the "tab" key where they can still interact with them.
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
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With