1
<form name="form" aDisabled="true" bDisabled="false">
<fieldset id="a">
<input> 
...
</fieldset>
<fieldset id="b">
<input> 
...
</fieldset>
</form>

So i want to make the fields under fieldset to be disabled when aDisabled is true and b to remain enabled, i tried the below jquery but this does not seem to work for me

$("[aDisabled='true'] input:not('#b')").attr('disabled', 'disabled');

2 Answers 2

1

You can disable all fieldset's inside your form except #b like this

$("[aDisabled='true'] fieldset:not(#b)").attr('disabled', 'disabled');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form name="form" aDisabled="true" bDisabled="false">
  <fieldset id="a">
    <input type="text">
  </fieldset>
  <fieldset id="b">
    <input type="text">
  </fieldset>
</form>

Sign up to request clarification or add additional context in comments.

7 Comments

$("[aDisabled='true'] fieldset:not(#b)").attr('disabled', 'disabled'); <script src="ajax.googleapis.com/ajax/libs/jquery/2.1.1/…> <form name="form" aDisabled="true" bDisabled="false"> <fieldset id="a"> <input type="text"> </fieldset> <input type="text"> </form> actually i have like this, there is just one fieldset
I don't understand your comment, can you create jsfiddle.net/Lg0wyt9u with your actual HTML and say what you want to disable.
i said what if there is no fieldset id="b" , there are just input fields in fieldset id="a" and some input fields directly inside form
Then you just select and disable fieldset with id a jsfiddle.net/Lg0wyt9u/753 or if you want to select specific element inside that fieldset you target them like this jsfiddle.net/Lg0wyt9u/755
yea but how do you inverse the condition than, disable the one that are at form level and not enable the one's under fieldset id="a"?
|
0

The problem with your selector is that input:not(#a) means "input without an ID of a" which is true for all your inputs. What you meant is "fieldset:not(#a)" or more accurately, "fieldset#b"

$("[aDisabled='true'] fieldset#a input").attr('disabled', true);
$("[bDisabled='true'] fieldset#b input").attr('disabled', true);

2 Comments

lets say i don't have fieldset id=b. how would i filter all except fieldset id=a?
fieldset:not(#a) as mentioned above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.