0

I am struggling with a problem which I presumed to be easy. I have a parent div, and inside my parent div I have many divs. I have onclick events attached to all these divs.

Now I have to disable those divs from taking click events when user clicks on them when the page is loading data via asyn ajax call.

I tried to disable div by using following:

       $(".theme-container").children().attr('disabled', true)

Where "theme-container" is the class name of the parent div. Unfortunately it is not working, and I still can click on divs!

Some help would be greatly appreciated.

2
  • what about .children().off()? That's the actual opposite of .on(...) Commented Mar 7, 2015 at 19:26
  • You can use .off('click') - see this answer to a similar question. Commented Mar 7, 2015 at 19:26

2 Answers 2

1

Try deactivating pointer events. Here is a CSS class:

.inactive {
    pointer-events: none;
}
Sign up to request clarification or add additional context in comments.

4 Comments

note that this doesn't have broad browser support. Makes more sense to remove the event handlers
Note: Not supported from mobile: developer.mozilla.org/en-US/docs/Web/CSS/…
@Petroff: As per this link, it's supported on mobiles too!
@mk117 hmmm on Mobile tab Basic support is "?". But thanks for the link. I have to test it by myself to be sure. +1 for your comment.
1

You should use namespaces to bind and unbind events.

function myAttachedEvent (event){
    $(".myDivs").unbind("click.myClick"); // here you "disable" the click event

    // do everything else and when you get the response bind the event again:
    $(".myDivs").bind("click.myClick",myAttachedEvent);
});

$(".myDivs").bind("click.myClick", myAttachedEvent);

Take a look at the unbind Jquery documentation and look for "Using namespaces" section.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.