I need to append the img inside an <a> tag. I have been hacking at this and no resolve, driving me crazy. If you can help that would be great. I am using jQuery 1.5
while condition{
    $("<img>").attr("src", thumb).appendTo("#images");
}
End result should be:
<a href="#"><img src="xxxxx"></a>
When I use prepend or appendto I get this result:
<div id="images src="xxxxxxx"><a></a> 
OR
<a href="#"></a><img src="xxxxx">
Thanks for any assistance.
With jQuery, you can dynamically create a new image element and append it at the end of the DOM container using the . append() method.
$("#images").append($("<a>", 
{
    href: "#", 
    html: $("<img>", { src: thumb })
}));
working example: http://jsfiddle.net/hunter/Rxkxg/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With