I have an html string from which I want to replace all my img
tags with figure
tag. Here is my code
$('img',$(html)).replaceWith(function(){
var figure = '<figure><img src="'+$(this).src+'"><figcaption>'+$(this).attr('alt')+'</figcaption></figure>';
return $(figure);
});
This code does not work. I would also like to return the resulting html string after the operation has been performed but it seems that replace only returns the element that has been replaced . So how do I do that?