Hello. I have an image on my website. I would like when I click it, it show a <div>
, and when I click it another time, it hides the <div>
.
How can I do this in JavaScript? Should I use jQuery?
views:
48answers:
2
+3
A:
You can do like this in JQuery:
<img id="img_id" src="image path here" />
<div id="mydiv" style="display:none;">Some content</div>
$('#img_id').toggle({
function(){$('#mydiv').show();},
function(){$('#mydiv').hide();}
});
First click on an element with id img_id
will show an element with id mydiv
and second click would hide it.
See more info about toggle() function.
Sarfraz
2010-04-10 09:13:39
And, don't I have to link the image?
Francesc
2010-04-10 09:17:29
@Francesc: As can be seen the `img_id` is supposed to be for an image. Thanks
Sarfraz
2010-04-10 09:18:34
@Francesc: please see my updated answer. Thanks
Sarfraz
2010-04-10 09:22:31