0

How do you import an image in JavaScript

I am trying to make a card for my friend using JavaScript. How do I import images into my document? PS the tag isn’t relevent it was just the only tag I could think of

30th Sep 2018, 8:53 AM
AC Gaming
AC Gaming - avatar
5 Respuestas
+ 14
You can also use CSS to display images: #element { background-image: url("http://url.com"); } If you have several images, you can create an array with their URLs. Using for loop and DOM functions you can create elements in the document with these URLs. var urls = ["image URL 1", "URL 2"]; for (var url of urls) { var i = document.createElement("img"); i.setAttribute("src", url); document.body.appendChild(i); }
30th Sep 2018, 9:55 AM
Igor Makarsky
Igor Makarsky - avatar
0
It depends on how you want to use the image. It might be simpler just to do it the standard HTML way. Otherwise... https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_img_create
30th Sep 2018, 9:58 AM
Janning⭐
Janning⭐ - avatar
0
sorry im a noob whats the HTML way?
30th Sep 2018, 9:59 AM
AC Gaming
AC Gaming - avatar
0
No worries. https://code.sololearn.com/W1HE74c6JmEX/?ref=app The link to the relevant SoloLearn lesson is within.
30th Sep 2018, 11:07 AM
Janning⭐
Janning⭐ - avatar
0
SsvsS | |
4th Mar 2024, 10:03 PM
Edward De Vera
Edward De Vera - avatar