Reputation: 42670
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.
Upvotes: 1
Views: 1616
Reputation: 1137
Use this method:
$('#my_id').replaceWith('<span id="my_id">abc</span>');
Upvotes: 1
Reputation: 114846
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);
Upvotes: 0
Reputation: 4507
$("#my_id").each(function(){
$(this).replaceWith("<a id=\"" + $(this).attr("id") + "\">" + $(this).text() + "</a>");
});
Upvotes: 3