开发者

Add change() function to all but last element of a class

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.


If I understand you question right:

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

should do it


lol on /*do nothing*/, try

$("select.prodOption:not(:last)").change(function(){...});


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜