Show/Hide Content with css and javascript
This example shows you how to create a show/hide container using a 2 links “Show Content” and “Hide Content”, with CSS, and some JavaScript to manipulate our CSS.
See below source code and enjoy show/ hide DIV Content magic……
Source Code:
<!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Show/ Hide DIV Container</title> <script language="javascript" type="text/javascript"> function Show_Hide_Content(div_id) { if (document.getElementById(div_id)) { if (document.getElementById(div_id+'-showDIV').style.display != 'none') { document.getElementById(div_id+'-showDIV').style.display = 'none'; document.getElementById(div_id).style.display = 'block'; } else { document.getElementById(div_id+'-showDIV').style.display = 'inline'; document.getElementById(div_id).style.display = 'none'; } } } </script> <style type="text/css"> .hide_div{display: none;} </style> </head> <body> <div style="width:600px;"> <h1>Show/Hide DIV Content</h1> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.<br /><a href="#" id="example1-showDIV" onclick="Show_Hide_Content('example1');return false;">Show details</a></p> <div id="example1" class="hide_div"> <p> Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.<br /> <a href="#" id="example1-hide" onclick="Show_Hide_Content('example1');return false;">Hide details</a></p> </div> </div> </body> </html>