How to create a hidden <img> in JavaScript?
5 answers
I'm not sure I understand your question. But there are two approaches to making the image invisible ...
Pure html
<img src="a.gif" style="display: none;" />
Or...
HTML + Javascript
<script type="text/javascript">
document.getElementById("myImage").style.display = "none";
</script>
<img id="myImage" src="a.gif" />
+39
, Javascript. .
function loadImages(src) {
if (document.images) {
img1 = new Image();
img1.src = src;
}
loadImages("image.jpg");
The image will be requested, but until you show it, it will never be displayed. Great for preloading the images that you expect from requests but delaying them until the document is loaded.
+3