JQuery add <a> tag around <img>
2 answers
This will complete the set of images with links to them:
$('some selector for the images').each(function() {
$(this).wrap("<a href='" + this.src + "'/>");
});
... uses .each( link ), .wrap( link ) and the DOM src() property for image elements.
Edit Or, if Pointy points out (but not clearly), just pass the function to wrap:
$('some selector for the images').wrap(function() {
return "<a href='" + this.src + "'/>";
});
+21