Reputation: 1477
I'm trying to append a new image DOM object to a div
but it is not including any of the image DOM's attributes.
$linkedImage = $('<a></a>', {href: "javascript:void"})
.addClass('myNextImage')
.append('<img />', {alt: "MyImage", src: $imageURL});
this._div.append($linkedImage);
What this shows up as is:
<a href="javascript:void" class="myNextImage"><img></a>
Without the alt and src tags.
Upvotes: 1
Views: 91
Reputation: 6334
Before you append it create the image element like you did with the anchor element.
$linkedImage = $('<a></a>', {href: "javascript:void"})
.addClass('myNextImage')
.append($('<img />', {alt: "MyImage", src: $imageURL}));
this._div.append($linkedImage)
Upvotes: 2