1

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?

j08691
  • 204,283
  • 31
  • 260
  • 272
genz
  • 35
  • 2
  • 6

3 Answers3

4

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

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
1

seems like you should be doing something like

$("#center").children().not("#menu");
Jason Fingar
  • 3,358
  • 1
  • 21
  • 27
0

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.

speedingdeer
  • 1,236
  • 2
  • 16
  • 26