7 Answers
7

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.

Great tip about the interactive tester! I got a couple of things to work: $("#featured > :not('select')") and $("#featured").children().not("select") buy very strangely not $("#featured").children().not("#selectorId") and not $("#featured > :not('#selectorID')")
–
Shawn J. GoffJul 14 '09 at 15:35

1

Omit the quotes. Just use :not(seletor), so :not(#selectorID) and it'll work fine.
–
Martijn Pieters♦Jul 14 '09 at 15:47

Thanks for the tip about the traversing method. I got it to work by $("#featured").children().not("select") Also I found it very strange that $("#featured").children().not("#selectorId") does not work in this case.
–
Shawn J. GoffJul 14 '09 at 15:25

id searches may be case-sensitive (not sure). You can always use the form attributes. Form elements usually have names, so you could use: "select[name=selectname]". But getting via id is always faster.
–
JeffJul 14 '09 at 15:46

The :not(selector) does exactly this, and it comes in a couple styles. You can use the selector, or the method. Below is an example of using the selector:

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

This will match any child within #container that is not a <select> element. Then we have the method fashion of exclusion, which goes by the same name, but must be ran differently:

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

This runs against the children of the matched elements. In this case, .not acts as a filter. Which brings me to the next example, using .filter() to get the results you want. With this method, we can provide our own custom function to rummage through the results and pick the ones we want:

In this example, we select all of the children of #container, and then pass them through a filter that we have defined called "isNotSelect". Within our filter, we return either true or false for every element. If we return true, that element will be returned to the result set. If we return false, that element will be removed from the result set. We're asking if the element is not a select. This will return false for all select elements, thus removing them from our collection.

It is not clear what you actually want from your question.
:not(select) will filter out the select from all the descendants but it will not out the select descendants. If this is your issue then try the following