How can you make a simple tag like <img src="a.gif"> hidden programmatically using JavaScript?
-
1Can you clearly state what you wanna do?Billy– Billy2009-06-15 15:07:39 +00:00Commented Jun 15, 2009 at 15:07
-
4<img src="a.gif" style="display:none">joe– joe2009-06-15 15:11:03 +00:00Commented Jun 15, 2009 at 15:11
-
I got the answer , Billy Could you please edit it to understandablejoe– joe2009-06-15 15:13:12 +00:00Commented Jun 15, 2009 at 15:13
Add a comment
|
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" />
2 Comments
ReyAnthonyRenacia
what if i want to show the image? should it be .style.display = true; ?
Steve Wortham
To show the image it'd be
.style.display = "inline-block" which would be the default display behavior of an img. All possible display options are described here... css-tricks.com/almanac/properties/d/displayThis question is vague, but if you want to make the image with Javascript. It is simple.
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 pre loading images you expect to be requests but delaying it until the document is loaded.