Question

I'm trying to exclude one block from my jquery selection.

I have the following html structure:

<div id="center">
    ...
    <div id="menu>
        <!-- menu -->
    </div>
    ...
</div>

Now I want to select all elements from #center except for the menu. That's why my jquery look like this:

$("#center").not("#menu")....

But this seems to select exactly the same as

$("#center")....

I also tried

$("#center:not(#menu)")....

And this also gave me the same result. So how can I select all elements from a div without a certain div?

Was it helpful?

Solution

I guess you want to select other divs that are siblings of #menu and are child of #center:

$("#center> *").not("#menu");

working Demo

For all contents:

$("#center *").not("#menu");

working Demo

OTHER TIPS

seems like you should be doing something like

$("#center").children().not("#menu");

Selects all with id='center' which doesn't have id='menu'

$("#center").not("#menu")

logically doesn't make much sense.

You should use

$("#center *").not("#menu");

instead which selects all elements inside center which don't have id=menu.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top