Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - Multiple Selectors in a :not()?

I cant seem to get the following working:

$('input:not([type=radio][type=checkbox])').live('click', function() {     alert("You haven't clicked a radio or checkbox!"); }); 

Have tried a few different syntax's, can anyone help me out on this one.

Cheers
Charlie

like image 612
Charlie Sheather Avatar asked May 29 '11 09:05

Charlie Sheather


People also ask

Can we use multiple selectors in jQuery?

You can specify any number of selectors to combine into a single result. This multiple expression combinator is an efficient way to select disparate elements. The order of the DOM elements in the returned jQuery object may not be identical, as they will be in document order.

Can you chain selectors in jQuery?

With jQuery, you can chain together actions/methods. Chaining allows us to run multiple jQuery methods (on the same element) within a single statement.

How do you say not in jQuery?

jQuery :not() SelectorThe :not() selector selects all elements except the specified element.


1 Answers

You're confusing the multiple selector with the multiple attribute selector. You should write:

$("input:not([type=radio], [type=checkbox])"); 

The multiple attribute selector [type=radio][type=checkbox] matches the elements whose type attributes are equal to both radio and checkbox, which cannot happen in this universe.

like image 191
Frédéric Hamidi Avatar answered Sep 21 '22 05:09

Frédéric Hamidi