1

How would one select the text inside a span that looks like this?

<span class="season">
  <ul class="productBullet">....</ul>
  "This is the text I want to select (without the ul above).
</span>
docta_faustus
  • 2,383
  • 4
  • 30
  • 47
  • http://stackoverflow.com/questions/13017894/how-to-get-text-node-after-element – maraca Apr 23 '15 at 17:57
  • 1
    This refers to exactly what you're trying to achieve: http://stackoverflow.com/questions/3442394/jquery-using-text-to-retrieve-only-text-not-nested-in-child-tags – mickzer Apr 23 '15 at 18:01
  • 1
    http://stackoverflow.com/questions/3442394/jquery-using-text-to-retrieve-only-text-not-nested-in-child-tags I would use this one – dmg_ Apr 23 '15 at 18:04
  • @Andy Question appear to be different from http://stackoverflow.com/questions/3442394/jquery-using-text-to-retrieve-only-text-not-nested-in-child-tags ? See _"after a
      "_ at OP ? More than single `#text` node appear within `html` at Question.
    – guest271314 Apr 23 '15 at 18:31
  • @guest271314 They appear to be the same for me. Could you point out the difference? Even the answer you gave is almost the same than the second highest rated answer of the other question – Andy Apr 23 '15 at 18:38
  • 1
    @Andy See at OP _"Select text inside a **after** a
      "_ . The referenced Answer at http://stackoverflow.com/a/14755309/2801559 would return _two_ `#text` nodes ; both `#text` node _within_ `ul` `....` , _and_ `#text` node after `ul` `"This is the text I want to select (without the ul above).` https://jsfiddle.net/3wwk5e4x/
    – guest271314 Apr 23 '15 at 18:55

1 Answers1

1

Try

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>
guest271314
  • 1
  • 15
  • 104
  • 177