close

How to disable clicking inside div

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How to disable clicking inside div in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How to disable clicking inside div ?

  1. How to disable clicking inside div ?

    disable clicking inside div 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:

  2. disable clicking inside div

    disable clicking inside div 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:

Method 1

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

Method 2

You can disable the event by applying following code:

with .attr() API

$('#your_id').attr("disabled", "disabled");

or with .prop() API

$('#your_id').prop('disabled', true);

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment