jQuery - Multiple Selectors in a :not()?

JqueryJquery Selectors

Jquery Problem Overview


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

Jquery Solutions


Solution 1 - Jquery

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.

Solution 2 - Jquery

The syntax inside the not() is identical to the normal selector syntax, so if you want to match things that are not either of those things, you use a selector in the not that would match both (since essentially you're negating the selector). How do you do that? The same way you apply styles to multiple selectors at once in CSS, with a comma, as so:

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

That should select all inputs the not [type=radio] and not [type=checkbox]

Solution 3 - Jquery

You can also exclude items like this:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCharlie SheatherView Question on Stackoverflow
Solution 1 - JqueryFrédéric HamidiView Answer on Stackoverflow
Solution 2 - JquerydarkliquidView Answer on Stackoverflow
Solution 3 - JqueryJunaid AnwarView Answer on Stackoverflow