How to change only HTML text?
How to change this?
<p>Please change me</p>
Can I change “Please Change Me” without using replaceWith("<p>This is been changed.</p>")?
replaceWith()Modifies all HTML content, including the tag <p>.
Is there a way to get "Please Change Me"? And not including the tag <p>... then change it to something like "This has been changed."
+5
5 answers
Just do
// I'm just changing the text content
$('p').text('This has been changed.');
or even
$('p').html('This has been changed.');
The latter should really be used only if your content contains HTML markup, for example:
$('p').html('<span>This has been <strong>changed</strong></span>.');
+3