Reez0
Reez0

Reputation: 2687

How to create an anchor tag with an img tag inside

I'm trying to recreate an element like this:

 <a href='https://www.myapp.com/'><img class='footer-img' src="{% static 'assets/banner/ADB_SOF-01.jpg' %}"></a>

I have this so far, but not sure where to go with adding the img tag inside it.

var $a = $("<a>", {href: value.url});
$("#banner").append($a)

Upvotes: 0

Views: 28

Answers (1)

trincot
trincot

Reputation: 351369

You can use append to include the img:

var $a = $("<a>", {href: value.url}).append(
    $("<img>", {src: "{% static 'assets/banner/ADB_SOF-01.jpg' %}"})
);

Upvotes: 2

Related Questions