Combining AND and OR in jQuery selectors

I have a jQuery selector with the following syntax:

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

Thus, this creates certain functionality for all components that have an image type and do not have the xyzClass class.

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

We need an OR condition with a class condition. Such that Any component that is β€œinput” of type as image must be selected IF

  • class is not xyzClass OR
  • id contains the string someIdString

Could you help with modifying an existing selector?

Greetings.

+1
jquery css-selectors
source share
3 answers

Updated Answer

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

For your updated question, although this is not optimized, I would recommend specifying as many as you can.

Original answer:

 function someSpecificFunctionality() { } $(els) .click(someSpecificFunctionality) .data('someSpecificFunctionality', true) $(els).filter(function() { return $(this).not('.xyzClass') && $(this).data('someSpecificFunctionality') == true }); 
+2
source share
 $(":image:not(.xyzClass),:image[onclick*='someSpecificFunctionality']"); 
+2
source share

for "OR" use a comma:

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

I'm not sure how you define onclick: is it in your HTML or is it added programmatically?

0
source share

All Articles