How do I use jQuery to select all children except a select element

You can simply omit the wildcard as it is optional in this case, but keep the space:

$('#container :not(select)');

Alternatively, use the .not() method to filter out the select after selecting all children:

$('#container').children().not('select');

If your problem is that children of select are still included, you could explicitly filter those out with the .not() method:

$('#container').children().not('select, option, optgroup');

or select direct children only:

$('#container > :not(select)');

You can try out jQuery selectors at the interactive jQuery selector tester for quick feedback; try for example div :not(ol) or div > :not(ol) to get a feel for what difference the direct child (>) selector makes.

Leave a Comment