Multiple selectors in jQuery

2019-06-21 19:32发布

问题:

I'm trying to run this code:

$("input[value='OK'][value='Recrutar'][value='Criar'][id!='attack_name_btn']").click();

So, as you see, I'm trying to select a input that has a value equal to "OK" or "Recrutar" or "Criar" and they may not have an id called "attack_name_btn".

But it's not working.

I ckecked this too, multiple selectors jquery

回答1:

Your code is actually doing an 'and' not an 'or'. What you have is the multiple attribute selector, but what you want is the multiple selector and then filter the results of that.



回答2:

Use multiple selectors to get all objects that match any of them like this and then filter out the ones you don't want:

$("input[value='OK'], input[value='Recrutar'], input[value='Criar']".filter("[id!='attack_name_btn']").click();