Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

show/hide image on click

I need to show/hide image in html page. I thought its very simple. But why I am getting error 'visible' undefined.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Ajax Test
    </title>
    <script type="text/javascript">
<!--
    function showImage(){
        document.getElementById('loadingImage').style.visibility=visible;
    }

    -->

    </script>
    </head>
<body>
    <input type="button" value="Ajax Button" onclick="showImage();"/>
    <img id="loadingImage" src="ajax-loader.gif" style="visibility:hidden"/>

</body>
like image 678
crazyTechie Avatar asked Jan 04 '10 11:01

crazyTechie


People also ask

How do you hide and show on click?

Projects In JavaScript & JQuery To show and hide div on mouse click using jQuery, use the toggle() method. On mouse click, the div is visible and on again clicking the div, it hides.

How do I show hidden images in HTML?

Style display property is used to hide and show the content of HTML DOM by accessing the DOM element using JavaScript/jQuery. To hide an element, set the style display property to “none”.

How can we hide an image on a button click using jQuery?

We have used a click() method which will be called when the button of id(hide) will be clicked and another click() method will be called when another button of id(show) will be click.


2 Answers

You need to put it in quotes - it's a string:

document.getElementById('loadingImage').style.visibility='visible';
like image 171
David M Avatar answered Oct 15 '22 10:10

David M


I would use Jquery. Go download it at the Jquery home page.

Then, include it:

<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
function showImage(){
$("#loadingImage").toggle();
}

</script>


<img id="loadingImage" src="ajax-loader.gif" style="display:none;"/>
like image 39
TIMEX Avatar answered Oct 15 '22 12:10

TIMEX