jQuery:在<ul>之后选择<span>中的文本

时间:2015-04-23 17:55:46

标签: jquery

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

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

1 个答案:

答案 0 :(得分: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>