NullVoxPopuli
NullVoxPopuli

Reputation: 65103

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?

Upvotes: 6

Views: 628

Answers (2)

Chandu
Chandu

Reputation: 82893

Try this:

$("#YOUR_DIV a").click(function(){
 return false;
})

Upvotes: 2

lonesomeday
lonesomeday

Reputation: 237847

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.

Upvotes: 3

Related Questions