Q:

transform div into h2 span jQuery

I have a div with a generated title dynamic title
<div class="title">dynamic content</div>

and i would like to transform it like so:
<h2 class="title"><span>dynamic content</span></h2>

Would that be doable in jQuery?

A:

This should do it.
$('div.title').replaceWith(function() { 
    return $('<h2>').addClass('title').append($('<span>').text($(this).text()));
});

http://jsfiddle.net/uPFUu/

