If I have something like:
<h2> test text </h2>
How would I use JavaScript to make it so that the text is now within a paragraph tag:
<p> test text </p>
I was thinking I could do something like:
var text = ('h2').text();
('h2').replace('<p>' + text + '</p>');
But it did not quite work.
In vanilla JS, select the element, create a
<p>
element, and usereplaceWith
to replace the<h2>
with the new<p>
: