Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

transform div into h2 span jQuery

Tags:

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?

like image 426
user472285 Avatar asked Jun 29 '11 12:06

user472285


1 Answers

This should do it.

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

http://jsfiddle.net/uPFUu/

like image 148
Richard Dalton Avatar answered Oct 21 '22 22:10

Richard Dalton