【问题标题】:jQuery: Select text inside a <span> after a <ul> [duplicate]jQuery:在 <ul> 之后选择 <span> 内的文本 [重复]
【发布时间】:2015-07-02 01:57:53
【问题描述】:

如何选择看起来像这样的跨度内的文本?

<span class="season">
  <ul class="productBullet">....</ul>
  "This is the text I want to select (without the ul above).
</span>

【问题讨论】:

标签: jquery


【解决方案1】:

试试

var text = $(".season").contents().filter(function(i, el) {
  return this.nodeType === 3 && $(this).prev().is("ul")
}).text();


$("body").append("<br /><br />selected text: " + text);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<span class="season">
  <ul class="productBullet">....</ul>
  "This is the text I want to select (without the ul above).
</span>

【讨论】:

    猜你喜欢
    • 2018-10-28
    • 1970-01-01
    • 1970-01-01
    • 2015-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-27
    相关资源
    最近更新 更多