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
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);
}
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
0
sorry im a noob whats the HTML way?
0
No worries.
https://code.sololearn.com/W1HE74c6JmEX/?ref=app
The link to the relevant SoloLearn lesson is within.
0
SsvsS
|
|