0

I've been puzzling over this one for days.

I have a CMS that sometimes doesn't put text inside of a paragraph when it should. I have no control over the produced HTML. Say I have multiple divs on the page that look like this:

<div class="myclass">
    Unparented text
    <p>Parented text</p>
    More unparented text
    <p>More parented text</p>
</div>

How would I update the div so that each section of unparented text is surrounded in its own <p> tag?

  • Do you want to change the text or the p tags? – Güney Saramalı Oct 10 '17 at 09:39
  • If you bothered to search, there are already [several answered questions on StackOverflow that addresses your issue](https://stackoverflow.com/search?q=wrap+textnode). – Terry Oct 10 '17 at 09:45
  • I did search extensively, but not with those keywords. – Alex Douglas Oct 10 '17 at 09:46
  • Explore `.contents()` [https://api.jquery.com/contents/] and extrapolate from there. See also: https://stackoverflow.com/questions/37506770/find-text-in-element-that-is-not-wrapped-in-html-tags-and-wrap-it-with-p AND: https://stackoverflow.com/questions/13836633/jquery-wrap-all-unwrapped-text-in-p-tags – UncaughtTypeError Oct 10 '17 at 09:49

0 Answers0