如何选择看起来像这样的跨度内的文本?
<span class="season">
<ul class="productBullet">....</ul>
"This is the text I want to select (without the ul above).
</span>
答案 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>