This is how I do it. Suppose you need to do this on an h3 tag:
var h3tag = $('h3#head'); var txt = h3tag.text(); h3tag.text(''); //Remove default text $("<a />", { "href" : $('h2 a').attr('href'), //grab the link from somewhere "text" : txt }).appendTo(h3tag);
Hope this helps.
source share