views:

612

answers:

3

Hi all.

I have a jquery selector with following syntax.

$('input[type=image]').not(".xyzClass").click(function{//some functionality})

So this puts a specific click functionality for all the components which are of type image and does not have class "xyzClass".

*I have modified the question to reflect latest changes, some of the answers below are correct for previous version but may not hold correct for modified version. Apologies for that.

We need an OR condition with class condition. Such that Any component which is "input" having type as image, should be selected IF 1. class is not "xyzClass" OR 2. id contains string "someIdString"

Could you please help with the modification in existing selector?

Cheers.

A: 

to do an "OR" use a comma:

$('input[type=image]')
    .not(".xyzClass,[onclick*='someSpecificFunctionality()']")
    .click(...);

I'm not sure how you're defining the onclick though: is it in your HTML or is added programmatically?

nickf
this will put a not condition on second "onClick" check also. Isn't it? Which is not the solution we want.
Priyank
oh - the question was a bit ambiguous in its original form.
nickf
+1  A: 

Updated answer

$('*:not(.xyzClass)[id*=containsThisValue]')

For your updated question, though this isn't optimized I would recommend specifying as much as you can.

Original answer:

function someSpecificFunctionality() {
}

$(els)

.click(someSpecificFunctionality)
.data('someSpecificFunctionality', true)


$(els).filter(function() {

    return 
        $(this).not('.xyzClass') && 
        $(this).data('someSpecificFunctionality') == true

});
meder
Accepting this as the answer as this is more flexible way considering I may have more conditions in future.
Priyank
+2  A: 
$(":image:not(.xyzClass),:image[onclick*='someSpecificFunctionality']");
RaYell
Thanks. that helped me get the right answer.
Priyank