I have a situation where the following code is getting written to my page.
Some text here which is not wrapped in tags
Some mor
Ran into a similar need and attempted to employ the solution @Arash_Milani. Solution worked, however I ran into conflicts when the page also required to make ajax calls.
After a bit of digging, I found a fairly straight-forward solution on api.jquery.com using the .contents() method:
$('.wrapper').contents().filter(function() {
return this.nodeType === 3;
}).wrap('').end();
p.good {
color: #09f;
}
p.fixed {
color: #ff0000;
text-align: center;
}
Some plain text not wrapped in any html element.
This text is properly wrapped in a paragraph element.