Is it possible to shorten these jQuery snippets by chaining them together? For the second chain, I’d like to get rid of the w class if possible.
$('#content').prepend("<h1 />");
$('#content h1').append( $('#content>p:first strong').html() );
$('#content>p:first strong').parent().remove();
$('font').wrapInner('<p class="w"/>');
$("p.w").unwrap().unwrap();
Edit: Let me clarify my second jQuery snippet. I’m cleaning up old HTML markup that looks like this:
<div id="content">
<p>
<font>
<b>Sample Title</b>
<br>
More sample text.
</font>
</p>
</div>
And changing it to this:
<div id="content">
<p>
<b>Sample Title</b>
<br>
More sample text.
</p>
</div>
This is how I would do it:
From the docs: http://api.jquery.com/jQuery/#jQuery2
So, you can pass an object literal as the second argument. That object literal “initializes” the newly created DOM element (the H1 element in our case).