开发者

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()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜