0

假设这是 DOM:

<body>
    <h1>Hello World</h1>
    <div class="tooltip">
       <div class="tooltip-hd">
         This is a Tooltip for header.
       </div>
       <div class="tooltip-bd">
         Some more info about header
       </div>
    </div>

    <div class="container">
       <h2>Subheading</h2>
       <div class="tooltip">
         <div class="tooltip-hd">
           This is a Tooltip for header.
         </div>
         <div class="tooltip-bd">
           Some more info about header
         </div>
       </div>

       <p>Contents inside subheading</p>
    </div>

</body>

我想选择身体内的所有孩子,不包括“工具提示”类下的孩子

$("body").find("*").not(".tooltip") 将选择项目

4

1 回答 1

1

I'm not sure why you'd want to do this, but the following would work (though I imagine it doesn't perform very well as it's filtering everything in the body):

var items = $('body').find('*').filter(function() {
  return !$(this).is('.tooltip') && !$(this).closest('.tooltip').length;
}).get();

This will exclude all elements which have the class .tooltip, and all elements which have an ancestor with the class .tooltip, so you'd end up with the following:

h1, div.container, h2, p

于 2013-08-01T10:35:54.693 回答