tags:

views:

1318

answers:

3

Hi everyone!!

I have 2 <fieldset> on my page, but one of them should have all of it inside elements disabled depending on some user's choice.

I have inside it input texts, selects and links. Is there a way to disable all of them instead of disable one by one?

Thanks!!

+5  A: 

What about using the children selector?

$.("#myfieldeset").children().attr("disabled", "disabled");

You can also filter the children selection:

$.("#myfieldeset").children("a,input")
kgiannakakis
Thanks!! I used something similar but your explanation will be useful for other thing I have t do! :-)
AndreMiranda
+3  A: 

Assuming you set a class="disableMe" on the fieldset you want to disable any input elements then the following code should do what you need:

$('fieldset.disableMe :input').attr('disabled', true)
pjesi
A: 

If for some reason you can't add an ID to the fieldset (which is usually preferred), you can always do this to hide all it's children elements:

$('fieldset:first > *').attr('disabled','disabled');
KyleFarris