A combination of AND and OR in jQuery selectors

后端 未结 3 945
时光取名叫无心
时光取名叫无心 2021-01-16 06:10

I have a jQuery selector with following syntax:

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

So

相关标签:
3条回答
  • 2021-01-16 06:46
    $(":image:not(.xyzClass),:image[onclick*='someSpecificFunctionality']");
    
    0 讨论(0)
  • 2021-01-16 07:06

    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
    
    });
    
    0 讨论(0)
  • 2021-01-16 07:07

    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?

    0 讨论(0)
提交回复
热议问题