Using Javascript of jQuery I want to swap a string of text for an html tag, over and over, without losing the previous html.
<p>This is <i id="text">text</i> and more text</p>
This is text and more text
function rep() {
var t = $('p').text().replace('text', '<b>html</b>');
$('p').html(t);
}
Ideally it would look like:
<p>This is <i id="text"><b>html</b></i> and more <b>html</b></p>
This is html and more html
I DONT want to change the pre-existing html. <i id="text">
should remain in the html, no matter how many times I run the function. .html().replace(..
wouldn't work because it will grab the id="text"
. Thanks.