JQuery: how to disable everything inside a div? but still keep everything visible?

The goal is to disable all links when clicked, and then disable all links until the server sends an inextricable command (using a similar method that will be used to disable).

So, since all links in one contain a div, I suppose I can just temporarily disable this.

How can i do this?

+6
javascript jquery
source share
2 answers

If you just want to disable the default link behavior, you can use a combination of delegate and event.preventDefault :

 $('#container').delegate('a', 'click', function(e) { if (linksDisabled) { e.preventDefault(); } }); 

You can then set linksDisabled (in the parent scope) to true or false in your other event handlers, if necessary.

If these links do Javascripty stuff, it's a little trickier. Probably the easiest way is to put an if (linksDisabled) in each event handler.

+3
source share

Try the following:

 $("#YOUR_DIV a").click(function(){ return false; }) 
+2
source share

All Articles