I've run into a problem that I don't know how to solve.
I need to wrap each grouping of <h2>
and <p>
tags with a containing <article>
tag.
My current HTML looks something like this:
<h2 category="someCategory">
<p>text text text<p>
<h2 category="anotherCategory">
<p>text text text<p>
<p>text text text<p>
I need to use javascript to make it look like this:
<article>
<h2 category="someCategory">
<p>text text text<p>
</article>
<article>
<h2 category="anotherCategory">
<p>text text text<p>
<p>text text text<p>
</article>
Somehow the javascript needs to figure out that each new <h2>
tag is the start of a new article element. And then that and the last <p>
tag before the next <h2>
tag will be end of the article.
(The bigger picture is that I'm parsing a markdown document and need the <article>
tags as css hooks for layout.)
I have no idea how to begin solving this problem, so I would be grateful of any help!!
- d13
UPDATE: Thank you!! I've tried both answers and they both work perfectly!