Laurence
Laurence

Reputation: 409

Jquery Selecting Form Items Conditional on ID

I have a form and I want to disable all the Elements that do not match a given ID using jquery

here is the basic logic I'm trying to achieve

for (AllElementsInthisForm){

    if(formElementID != specificid)
    {
       disable
    }
}

I hope that makes sense. Any ideas?

Upvotes: 1

Views: 183

Answers (3)

Gazler
Gazler

Reputation: 84140

There is a :not selector.

$('#FORMID input:not(#IDNAME)').attr('disabled', 'disabled');

Or an alternative sytax which is suitable for more complex conditions:

$('#FORMID input:not([id=IDNAME])').attr('disabled', 'disabled');

http://jsfiddle.net/wMUsg/

Upvotes: 4

Dennis
Dennis

Reputation: 32598

$('#form input:not(#excludeID)').attr("disabled", true);

Upvotes: 1

Fabian
Fabian

Reputation: 392

A class would make more sense in your case.

<div class="disableThis" />
<a class="disableThis />

<script>
    $('.disableThis').attr('disabled', 'disabled');
</script>

Upvotes: 0

Related Questions