What is the best JavaScript code to create an img element

前端 未结 11 2003
攒了一身酷
攒了一身酷 2020-11-28 20:46

I want to create a simple bit of JS code that creates an image element in the background and doesn\'t display anything. The image element will call a tracking URL (such as

11条回答
  •  旧时难觅i
    2020-11-28 21:10

    var img = document.createElement('img');
    img.src = 'my_image.jpg';
    document.getElementById('container').appendChild(img);
    

提交回复
热议问题