jQuery prevAll displaying text in backward ordering

Posted by SoulieBaby on Stack Overflow See other posts from Stack Overflow or by SoulieBaby
Published on 2010-06-06T22:29:08Z Indexed on 2010/06/06 22:32 UTC
Read the original article Hit count: 281

Filed under:
|
|

hi all, I'm trying to use jQuery to get all the paragraphs before the first h2 tag in my content. Here's the code I'm using:

$(".content").find("h2:first").prevAll().text()

Which is grabbing the content, although it's displaying it in backwards order. Example content:

<div class="content">
  <p>paragraph 1</p>
  <p>paragraph 2</p>
  <p>paragraph 3</p>
  <h2>First h2 tag</h2>
  <p>paragraph 4</p>
  <p>paragraph 5</p>
  <p>paragraph 6</p>
  <h2>Second h2 tag</h2>
</div>

The above code is outputting:

<p>paragraph 3</p>
<p>paragraph 2</p>
<p>paragraph 1</p>

Is there any way of reversing this, so it's in the correct order? I have tried using nextAll using different codes, but it seems to grab all of my content, or not work at all lol

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about div