Reputation: 7
I have created an image tag in JQuery. Now I need to add one more anchor tag with it. How can I implement it with JavaScript?
I tried this:
var imgg = document.createElement("img");
imgg.className='myclass';
$( ".myclass" ).add( "<a href="#">Test</a>" );
but it isn't working. It should appear as:
<img src=""><a href="#"></a>
Which function should I use to add one more anchor tag within img
tag?
Upvotes: 0
Views: 401
Reputation: 104775
Just do:
$("<img>").addClass("myclass").after("<a href='#'></a>").appendTo("body");
Upvotes: 1