I am working with a CMS that produces double break tags in place of my preferred paragraph tag. I tried:
$('<br /><br />').replaceWith('</p>');
Now after you finish laughing; could you please let me know if this is possible and if yes, the best way to approach this.
Update (from OP comment):
The paragraphs are not empty they have a <p>
tag at the start and the last para closes with a </p>
the paragraphs in between are spaced with the double <br>
tag.
I have no access to the editor code, which is my problem. It was custom build and awful.
There are a couple of ways you could try this. The preferable one (since you're already using jQuery) is probably using contents():
This will wrap all text nodes in paragraph tags. Follow that by ripping out all of the
tags:
Of course it gets more complicated if your text nodes aren't all simple children of the main text container.
The other (dirty) option is simply to mangle the html manually and then put it back in to jQuery once you're done:
I'm not saying the second way is wrong and sometimes it's the only way to get things done without rewriting everything. But it still makes me feel dirty if I have to do it ;-)