Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: how does one disable everything inside a div? but still keep everything visible?

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

So, since all the links are in one containing div, I figure I could just temporarily disable that.

How would I go about doing that?

like image 362
NullVoxPopuli Avatar asked Jan 31 '11 17:01

NullVoxPopuli


2 Answers

If you just want to disable the default link behaviour, 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 a parent scope) to true or false in your other event handlers as appropriate.

If these links are doing Javascripty things, it's a bit trickier. It would probably be easiest to put the if (linksDisabled) check in each event handler.

like image 130
lonesomeday Avatar answered Oct 31 '22 15:10

lonesomeday


Try this:

$("#YOUR_DIV a").click(function(){
 return false;
})
like image 27
Chandu Avatar answered Oct 31 '22 17:10

Chandu