I have a div (let\'s say the id is \"container\") with many elements in it, including a select element. I\'d like to select all everything in the div except the select. Thin
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.