I am making a game in javascript and I needed help with the following:
I want to make an image = to a variable then I only want to show the image when I want it too.
So I want the image by default hidden but it is always showing whatever I do. I am only a beginner and I have looked at this page and others on the internet to help me: http://www.roseindia.net/javascript/javascriptexamples/javascript-hide-image.shtml
This is the code so far:
<html> <head></head>
<body>
<img src="http://wwcdn.weddingwire.com/static/vendor/55001_60000/56375/thumbnails/64x64_SQ_1342622451725-Matangiaerial.jpg"
id="islandimg">
<script type="text/javascript">
var playermoney = 10000;
var islandarray = new array;
var car = 500; var watch = 100;
var diamond = 2000;
function hideImage() {
if (document.getElementById) {
document.getElementById('islandimg').style.visibility = 'hidden';
}
</script>
</body></html>
The code has other stuff in it for the game but ignore it.
You could use jQuery and do this:
UPDATE:
An other option would be this:
or this:
Whats the difference between the last two => http://webdesign.about.com/od/css/f/blfaqhidden.htm
It seams you want to toggle the visible state of the image so you should create a
showfunction too. (By using jQuery you can use thetoggle()function for that.)If you don’t want to display the image you could also hide it with
CSSby default and then toggle the display state withJavaScriptwith yourshowImage()function.or