views:

20

answers:

2

Hi, I have some content separated by <hr> markers. What I need to do is wrap everthing between the beginning maker and the ending marker.

Given this markup:

<hr class=begin>
 some content
 <some tags>
 more content
 <more tags>
<hr class=end>

This is what I need it to be:

<hr class=begin>
 <div class=content>
   some content
   <some tags>
   more content
   <more tags>
 </div>
<hr class=end>

I can do this with .nextAll() but it seems like there should be a more elegant solution.

+3  A: 

You can use .nextUntil() like this:

$("hr.begin").nextUntil("hr.end").wrapAll("<div class='content'></div>");
Nick Craver
+1 for that code too.
Sarfraz
@Nick - I'm going to accept your answer, as nextUntil() is the correct alternative to nextAll(), but neither method will not work for what I want to do because I also need to wrap free text that is between the markers. I'm going to re-ask the question with this specific. Thx!
+1  A: 

You are probably looking for .nextUntil() method of jQuery.

Get all following siblings of each element up to but not including the element matched by the selector.

Sarfraz