Reputation: 5424
This is my imgage:
<img alt="" id="loadingImage" src="Images/ajax-loader.gif" style="display:none"/>
I want to show the image with a javascript, this is my code and it does not work:
function changeDisplay() {
var img = document.getElementById('loadingImage');
img.style.display = "normal";
}
HOWEVER
If i do the "inverse", going from normal to hidden it works just fine with this code:
<img alt="" id="loadingImage" src="Images/ajax-loader.gif" style="display:normal"/>
function changeDisplay() {
var img = document.getElementById('loadingImage');
img.style.display = "none";
}
I dont get this, what am i doing wrong?
Upvotes: 3
Views: 10456
Reputation: 13798
First of all, as you can deduce for the answers and comments received, there is no normal
display.
Now, if when you say normal
you mean to go back to the default img
display mode, then you should go for display: inline
. Almost all the answers assumed that block
was the normal one. But img
is one of the inline elements, not a block element.
function changeDisplay() {
var img = document.getElementById('loadingImage');
img.style.display = "inline";
}
However, if when you say normal
you mean going back to the previous display mode it had before, the one calculated applying any CSS rule, then I would go for the solution proposed by @ArunPJohny comment. Just remove the display mode.
function changeDisplay() {
var img = document.getElementById('loadingImage');
img.style.display = "";
}
Upvotes: 5
Reputation: 345
u can use this function
function show() {
var contentId =
document.getElementById("loadingImage"); // Toggle
contentId.style.display == "block" ? contentId.style.display = "none"
: contentId.style.display = "block"; }
<img alt="" id="loadingImage"
src="http://upload.wikimedia.org/wikipedia/commons/c/c3/Wikipedia-logo-v2-pt.png" style=""/>
<a href="#" onclick="window.show()">toggle</a>
Upvotes: 1
Reputation: 978
Please try this
function changeDisplay() {
var img = document.getElementById('loadingImage');
img.style.display = "block";
}
Upvotes: 1
Reputation: 9
it seems there is no "normal" property value for display,but you can ues "block",to show the pic up.you can find more details form w3shools
Upvotes: 0
Reputation: 93
use display "block"
img.style.display = "block";
Hope this will help you!!
Upvotes: 1
Reputation: 11
style not have display:normal; Have's display:none; Not show display:block; Show
replace img.style.display = "normal"; on This img.style.display = "block";
function changeDisplay() {
var img = document.getElementById('loadingImage');
img.style.display = "block";
}
Upvotes: 1
Reputation: 5121
There is no display:normal
, but here is one example:
function show() {
var img = document.getElementById('loadingImage');
img.style.display = "inline";
}
function hide() {
var img = document.getElementById('loadingImage');
img.style.display = "none";
}
<img alt="" id="loadingImage"
src="http://upload.wikimedia.org/wikipedia/commons/c/c3/Wikipedia-logo-v2-pt.png" style=""/>
<a href="#" onclick="window.show()">show</a>
<a href="#" onclick="window.hide()">hide</a>
Upvotes: 1