Alex Dn
Alex Dn

Reputation: 5553

Disable elements inside of div

I have statement $("#myDiv").attr("disabled","disabled"); I thought that once I disable "parent" container, all elements inside of this become disabled. What I see actually, that text-box looks like disabled and "delete" not works within, but I can type there. check-box that inside of the same div, really looks disabled and I can't check/uncheck it. I'm not sure for 100%, but I think that I already used disabling that way and it worked as I expected (text-box not typeble). So I want to know if I need explicitly set disabled for textboxes or maybe some other CSS breaks what I'm expecting.

UPDATE: I know how to set disable explicitly for elements that i need, I just not want tot do it and what I'm asking that if it the only way to disable it, or textbox may work exactly as checkbox (without explicitly disabling it) and just some CSS breaks this behavior.

Upvotes: 2

Views: 1858

Answers (2)

Wesley
Wesley

Reputation: 2264

You can use the :input selector:

$("#myDiv :input").attr("disabled", true);

Upvotes: 1

Lee
Lee

Reputation: 10603

As far as im aware doing that is not cross browser friendly nor valid markup. Best option would be to do something like

$('#myDiv').find('input,textarea,select').attr("disabled", true);

That should find all form elements within the div and apply teh disabled flag directly

Edit: or even just

$('input,textarea,select', '#myDiv').attr("disabled", true);

Upvotes: 5

Related Questions