编写正确的jquery选择器以检索break标记后但在div内的文本

编写正确的jquery选择器以检索break标记后但在div内的文本,jquery,selector,Jquery,Selector,我有一些下面格式的代码,这些代码在我的页面中重复出现: <div class="video-description-secondary" style="display:block;"> <h2 class="two"> Some title text </h2> <br/> Some description text </div> 一些标题文本 一些描述文字 这里是我遇到的问题:我想使用jquery选择器检索描述

我有一些下面格式的代码,这些代码在我的页面中重复出现:

<div class="video-description-secondary" style="display:block;">
  <h2 class="two">
 Some title text
  </h2>
  <br/>
 Some description text
</div>

一些标题文本

一些描述文字
这里是我遇到的问题:我想使用jquery选择器检索描述文本(在br标记之后和结束div标记之前)。我不知道如何编写正确的jquery选择器来检索文本,因为文本本身不在它自己的标记内。我需要对该文本应用一些代码,以便正确地实现一个多读/少读链接


任何帮助都会很好。

您需要这份工作吗?从技术上讲,它抓住了所有不在子标签内的东西,而不是休息后的东西

替代溶液

这使您可以稍微控制返回的内容。检索所有文本节点,然后抓取最后一个


可以为其编写选择器,但我认为您应该重新评估您的设计。对您来说,只需将文本包装在一些标记中并选择它(这就是它的用途)就更容易了

所以这更好:

<div class="video-description-secondary" style="display:block;">
  <h2 class="two">
 Some title text
  </h2>
  <br/>
  <span class='special'>Some description text</span>
</div>

更干净。

jQuery通常可用于代码作者无法控制html内容的情况。例如,我可以很容易地想象上面的代码在firefox扩展中使用,该扩展与视频下载站点接口。@starwed truth,但您提到的约束没有指定。对于面临这个问题的人来说,这可能仍然是最简单的解决方案。
var textNodes = $('.video-description-secondary').contents().filter(function() {
    return this.nodeType == Node.TEXT_NODE;
});

var val = textNodes[textNodes.length - 1].nodeValue;
<div class="video-description-secondary" style="display:block;">
  <h2 class="two">
 Some title text
  </h2>
  <br/>
  <span class='special'>Some description text</span>
</div>
$('.special').text();