you could use $.delegate
http://www.danwebb.net/2008/2/8/event-delegation-made-easy-in-jquery

I haven't used it yet but it looks like life has just gotten easier.



On Feb 21, 5:03 pm, Sientz <[EMAIL PROTECTED]> wrote:
> I created this script to hide and show divs on a web page I am working
> on.  It is working properly as far as the effects on the page go.  I
> was just wondering if there is any way I can clean it up or make it
> simpler.  Thanks.
>
> $(document).ready(function(){
>
>   //THIS HIDES ALL LISTED DIVS ON LOADING OF PAGE
>   $('div.blackbook').hide();
>   $('div.canvas').hide();
>   $('div.pencil').hide();
>   $('div.murals').hide();
>   $('div.shows').hide();
>   $('div.tattoos').hide();
>   $('div.miscellaneous').hide();
>
>   $('a#blackbook').click(function() {
>     //HIDE DIVS
>     hide_divs();
>     //SHOW LISTED DIV
>     $('.blackbook').show('fast');
>     return false;
>   });
>
>   $('a#canvas').click(function() {
>     //HIDE DIVS
>     hide_divs();
>     //SHOW LISTED DIV
>     $('.canvas').show('fast');
>     return false;
>   });
>
>   $('a#pencil').click(function() {
>     //HIDE DIVS
>     hide_divs();
>     //SHOW LISTED DIV
>     $('.pencil').show('fast');
>     return false;
>   });
>
>   $('a#murals').click(function() {
>     //HIDE DIVS
>     hide_divs();
>     //SHOW LISTED DIV
>     $('.murals').show('fast');
>     return false;
>   });
>
>   $('a#shows').click(function() {
>     //HIDE DIVS
>     hide_divs();
>     //SHOW LISTED DIV
>     $('.shows').show('fast');
>     return false;
>   });
>
>   $('a#tattoos').click(function() {
>     //HIDE DIVS
>     hide_divs();
>     //SHOW LISTED DIV
>     $('.tattoos').show('fast');
>     return false;
>   });
>
>   $('a#miscellaneous').click(function() {
>     //HIDE DIVS
>     hide_divs();
>     //SHOW LISTED DIV
>     $('.miscellaneous').show('fast');
>     return false;
>   });
>
> });
>
> //HIDES ANY VISIBLE DIVS
>
> hide_divs = function() {
>
>     //HIDE ANY VISIBLE DIVS BEFORE CONTINUING
>     if ($('div.main').is(':visible')) {
>     $('div.main').hide('fast');
>     }
>     if ($('div.blackbook').is(':visible')) {
>     $('div.blackbook').hide('fast');
>     }
>     if ($('div.canvas').is(':visible')) {
>     $('div.canvas').hide('fast');
>     }
>     if ($('div.pencil').is(':visible')) {
>     $('div.pencil').hide('fast');
>     }
>     if ($('div.murals').is(':visible')) {
>     $('div.murals').hide('fast');
>     }
>     if ($('div.shows').is(':visible')) {
>     $('div.shows').hide('fast');
>     }
>     if ($('div.tattoos').is(':visible')) {
>     $('div.tattoos').hide('fast');
>     }
>     if ($('div.miscellaneous').is(':visible')) {
>     $('div.miscellaneous').hide('fast');
>     }
>
> }
>
> Do I need to use a div_switch = false somewhere in my script to call
> it back to null?  I'm not sure if I'm posing that question correctly,
> I'm just concerned about an open loop etc.

Reply via email to