views:

4439

answers:

3

I was under the assumption that if I disabled a div, all content got disabled too.

However, the content is grayed but I can still interact with it.

Is there a way to do that? (disable a div and get all content disabled also)

+4  A: 

Use a framework like JQuery to do things like:

function toggleStatus() {
    if ($('#toggleElement').is(':checked')) {
        $('#idOfTheDIV :input').attr('disabled', true);
    } else {
        $('#idOfTheDIV :input').removeAttr('disabled');
    }   
}

Disable And Enable Input Elements In A Div Block Using jQuery should help you!

Martin K.
"manually" selecting all inputs... I'll try that, but shouldn't it be sufficient to mark the div as disabled?
Juan Manuel
When I toggle to un-disable, some pagination buttons that need to remain disabled are also toggled...
Juan Manuel
You can filter this buttons and do a ".attr('disabled', true);" every time at them! Just do a $('#idOfPagination').attr('disabled', true); after the if{}else{} construct.
Martin K.
actually their status is controlled elsewhere, it depends on which page of the list I'm paginating I'm on (they don't always need to be disabled). I'd need someway of doing it without altering the content control's original status
Juan Manuel
+1 though .
Juan Manuel
You can check their status also with jquery and save it. Do: $('#idOfPagination').is(':disabled') ? disablePagination = false : disablePagination = true; once in a global area, directly after the page has been loaded.
Martin K.
+1  A: 

The disabled attribute is not part of the W3C spec for DIV elements, only for form elements.

The jQuery approach suggested by Martin is the only foolproof way you're going to accomplish this.

Chris Pebble
This answer should be the accepted answer, as if you're literally want to really disable DIV.
eriawan
+2  A: 

I just wanted to mention this extension method for enabling and disabling elements. I think it's a much cleaner way than adding and removing attributes directly.

Then you simply do:

$("div *").disable();
cletus
Yes, I implemented like that
Juan Manuel
This solution may cause side effects in big pages! (No static reference to a div container / Every underlying element is adressed)
Martin K.