I wish to use JQuery to replace (backward and forward)
<a id="my_id">abc</a>
to
<span id="my_id">abc</span>
May I know how I can do so in JQuery?
Thanks.
I wish to use JQuery to replace (backward and forward)
<a id="my_id">abc</a>
to
<span id="my_id">abc</span>
May I know how I can do so in JQuery?
Thanks.
$("#my_id").each(function(){
$(this).replaceWith("<a id=\"" + $(this).attr("id") + "\">" + $(this).text() + "</a>");
});
This has the benefit of transfering all attributes from the anchor to the span (not just the id).
var cacheAttr = $('#my_id').attr();
var newSpan = $('<span></span>').attr(cacheAttr);
$('#my_id').replaceWith(newSpan);