Hide/Show Part of a Page in JS
I have an image on my website. I would like when I click it, it show a <div>
, and when I click i开发者_开发知识库t another time, it hides the <div>
.
How can I do this in JavaScript? Should I use jQuery?
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.
Have a look at
- jQuery API .toggle()
- jQuery API .hide()
- jQuery API .show()
精彩评论