views:

15

answers:

3

Hi,

I am using jquery's change() to perform actions when SELECTs of a certain class are changed, however I do not want the last drop down in the DOM of this class to perform the action.

I have tried

$("select.prodOption").change(function(){
        if($(this) !== $("select.prodOption").filter(':last')){
            //do stuff
        }
 });

hoping that the called function would first check if this is the last element and only do the action if false.

I also tried adding a blank function seperately to the last element too, hoping this would overide the previous call, but both run instead.

$("select.prodOption").filter(':last').change(function(){ /*do nothing*/ });

Anybody got any ideas how I assing an onchange call to all but the last element of a class.

+1  A: 

lol on /*do nothing*/, try

$("select.prodOption:not(:last)").change(function(){...});
Reigel
Thanks guys, works a treat and boy were you fast.
Johnboy
you accepted the zero? hehe oh well.. ;) I'm always glad to help.. ;)
Reigel
+1  A: 

You can do it using the :not() selector to negate the :last like this:

$("select.prodOption:not(:last)").change(function(){
  //do stuff
});
Nick Craver
+1  A: 

If I understand you question right:

$("select.prodOption").not(':last').change(function(){          
        // do stuff
});

should do it

jAndy
Was the first check not enough? ;)
Nick Craver
thats what you got if you just copy'n'paste
jAndy
wahahahahhahaha lol!.... and you got the accepted answer... :D *thats what you got if you just copy'n'paste*
Reigel