views:

44

answers:

3

i have this code:

   function DisableDropDownsMonth() {
        $(".filterDropdown").val(0);
        $(".filterDropdown").attr("disabled", "disabled");
    }

to disable a bunch of select dropdowns that all have this class. I have a new requirement to call this on every ".filterDropdown" EXCEPT if the id = "#firstDropdown"

is there any syntax for this in jquery?

+5  A: 

You can use the :not() selector to exclude it, like this:

$(".filterDropdown:not(#firstDropDown)").attr("disabled", "disabled");

Or possibly judging by your ID, :gt() like this:

$(".filterDropdown:gt(0)").attr("disabled", "disabled");

This would disable all except the very first class="filterDropdown" in the DOM.

Nick Craver
@Nick - you are omnipresent . .
ooo
@ooo - nah, just got going for the day, answering some questions while this schema comparison takes forever :)
Nick Craver
I saw that question with no reply but when I clicked it had two answers and 5 up votes..that is quick +1 from for quick response.
Ayaz Alavi
+1  A: 

should be something like $(".filterDropdown:not(#firstDropdown)");

derek
Remember that a space is a *descendant* selector. You'll want to remove that for it to be correct.
patrick dw
must be $(".filterDropdown:not(#firstDropdown)");
Ayaz Alavi
good catch, edited
derek
+1  A: 

you can use following syntax

$(".filterDropdown[id!=firstDropdown]").attr("disabled", "disabled");

http://api.jquery.com/attribute-not-equal-selector/

Ayaz Alavi