I think I'd just do:
$('#nav a').html(function(i, html) {
return $.trim(html) == 'replace me' ? '<h2>Label</h2>' : html;
});
as I'm not very fond of :contains
, or
$('#nav a:contains(replace me)').html('<h2>Label</h2>');
as replaceWith()
will replace the entire anchor and not just it's content.