Show And Hide DIVs Using JQuery  

by Matt Hawkins, 10/01/2011
Categories : JavaScript

The jQuery library can be used to easily show or hide DIVs within your HTML pages. The following example shows how it can be done.

Include the jQuery libary in the head section of your HTML page :

<script src=\"\"></script>

You can download the jquery library from the jQuery website or use Google's version :

Now include the following Javascript functions in your HTML page <head> section :

<script type="text/javascript">
function togglebox(box_id) {
$("#" + box_id).fadeToggle("slow");
function showbox(box_id) {
$("#" + box_id).fadeIn("slow");
function hidebox(box_id) {
$("#" + box_id).fadeOut("slow");
// -->

You can then use the following Javascript function calls to show, hide or toggle the appropriate DIVs :


Where 'mydiv1' is the ID of the DIV you wish to fade.

Click here for an example page.

Author : Matt Hawkins  Last Edit By : Matt Hawkins
PHP Powered  MySQL Powered  Valid XHTML 1.0  Valid CSS  Firefox - Take Back The Web  EUKHost - Recommended Webhosting Solutions

MattHawkins CMS v3.0 - Copyright 2009-2022