How can I disable all elements inside a fieldset in jQuery?

André Miranda picture André Miranda · Apr 23, 2009 · Viewed 34.2k times · Source

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

The fieldsets contain text inputs, selects, and links. Is there a way to disable all of them instead of disabling them one by one?

Answer

kgiannakakis picture kgiannakakis · Apr 23, 2009

What about using the children selector?

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

You can also filter the children selection:

$("#myfieldeset").children("a,input");