<p class="bodytext">
<span class="datum">19.11.2015:</span>Some text <a href="path/to/link" title="some title" class="download">Some text</a>. Again some text!
</p>
<p class="bodytext">
<span class="datum">19.11.2015:</span>Maybe also only some text.
</p>
<p class="bodytext">
<span class="datum">19.11.2015:</span><a href="path/to/link" title="some title" class="download">Only with link</a>
</p>
Should be after jQuery:
<p class="bodytext">
<span class="datum">19.11.2015:</span>
<div class="someClass">Some text <a href="path/to/link" title="some title" class="download">Some text</a>. Again some text!</div>
</p>
<p class="bodytext">
<span class="datum">19.11.2015:</span>
<div class="someClass">Maybe also only some text.</div>
</p>
<p class="bodytext">
<span class="datum">19.11.2015:</span>
<div class="someClass"><a href="path/to/link" title="some title" class="download">Only with link</a></div>
</p>
So all HTML-Code after the </span>
should be wrapped in a div until the next occurence of </p>
What I tried:
$(".datum").each(function (index) {
$(this).nextUntil("p").andSelf().wrapAll("<div class='someClass' />");
});
Or:
$(".datum").nextUntil("p").wrap('<div class="someClass" />');
Didn't work either.