Jquery - How do I change the parent of an element from an H1 to a P?
I have <h1>heading</h1>
, how do I change it to <p>heading</p>
I think I could $.unwrap
then $.wrap
, but is there a better way?
$('h1').wrapInner('<p/>').children().unwrap();
This question is pretty close (I would consider it a duplicate) of How do I change an element (e.g. h1 -> h2) using jQuery / plain old javascript?
Using this solution, your answer would resemble
var p = $('h4');
var a = $('<p/>').
append(p.contents());
p.replaceWith(a);
Test it here: http://jsbin.com/abaja/edit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With