用于删除某些元素的jquery选择器

用于删除某些元素的jquery选择器,jquery,jquery-selectors,Jquery,Jquery Selectors,我有一个页面列表,每个页面都有下面的代码部分 <div class="A"> <br> some text. some <b>more</b> text. <br> More text to follow <a href="link">here</a> <br> <br> <div class="B"> <div class="z"

我有一个页面列表,每个页面都有下面的代码部分

<div class="A">
  <br>
  some text.
  some <b>more</b> text.
  <br>
  More text to follow <a href="link">here</a>
  <br>
  <br>
  <div class="B">
    <div class="z">
     <span class="y">text</span>
    </div>
  </div>
  <div class="C">text</div>
  <p>text</p>
  <div class="D">text</div>
</div> 


一些文本。 还有一些文字。
后面还有更多的文字

文本 文本 正文

文本

我想从B到D删除标记。我尝试了
slice()
,但效果不佳。我不能使用
n-last-child()
,因为在某些页面中child div标记的数量不同。有没有可能找到像
$('.a')。not('.B,.C,.D').html()
$('.a')。not('.B to.D').html()

首先你有一个打字错误,它不是

然后可以使用
find()

$('.A').find('.B、.C、.D').remove()


一些文本。 还有一些文字。
后面还有更多的文字

文本 文本 正文

文本
虽然dippas已经发布了一个简单的JavaScript替代方案,但似乎值得添加一个简单的JavaScript替代方案:

// find the parent element, here we use document.querySelector()
// which returns the first (if any) or null (if none) node
// matching he supplied selector:
document.querySelector('.A')

// from there we find the relevant descendent elements, using a
// CSS selector which returns a NodeList containing all elements
// matching the supplied selector(s):
.querySelectorAll('.B, .C, .D')

// using NodeList.prototype.forEach() to iterate over the
// NodeList result supplied from Element.querySelectorAll():
.forEach(

  // an Arrow function to apply to each of the Nodes in the
  // NodeList over which we're iterating; 'child' is a reference
  // to the current Node of the NodeList.

  // here we call ChildNode.remove() to remove the node:
  child => child.remove()
);
document.querySelector('.A').queryselectoral('.B、.C、.D').forEach(child=>child.remove())
*,
::之前,
::之后{
框大小:边框框;
保证金:0;
填充:0;
}
B
C
博士{
背景色:柠檬黄;
}


一些文本。还有一些文字。
后面还有更多的文字

文本 文本 正文

文本
参考dippas和David Thomas以及其他人的答案,我找到了适合我使用的应用程序的jquery选择器

$('.A').clone().children('.B,.C,p,.D').remove().end().html()

find()
未返回任何结果,并且
children()
删除了除B的子项之外的所有内容。无法使用
nth-last-of-type()
,因为有时div的编号会有所不同(将此更新为我的问题)。我使用了您的标记,它在代码段中起作用。运行它们是的,它在您的代码段中工作,但在我的应用程序或浏览器控制台中都不工作。那么您的标记与此不同,或者是其他错误