简体   繁体   中英

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)

You can use append to include the img :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM