Massimiliano Marini wrote:
Hi Sean,

You're on the right track. To only show one at a time, simply store
the last one open in a variable and close it before opening the new
one, here's an example:

Thank you for your help, your suggest have inspired me and I've writed
this code, I don't know if have sense or not, but work, any comment
suggest correction are welcome

The code I'm actually using

$("#scTopNavList li a").click(function(){
  var currOpen = ($(this).attr("href"));

  if($(currOpen).hide("fast")){
   $(currOpen).show("fast");
   return false;
  }else{
   $(currOpen).hide("fast");
   return false;
  }
 });


I don't think that's quite what you're after. If you're dealing with a bunch of links, you probably want to take a look at http://icant.co.uk/sandbox/eventdelegation/

I would give all of the actual divs you want to show/hide some common class (something more suitable than my example's "foobar"), or some other way of selecting them all, and do something like the following:


$("#scTopNavList").click(function( e ) {
    // Make sure it was an <a> that was clicked.
    var $a = $(e.target);
    if( !$a.is("a") ) return;

    // Get the <div> the href refers to.
    var $div = $( $a.attr("href") );

    // Make sure that <div> isn't already visible.
    if( $div.is(':hidden') ) {
        // Hide any currently visible <divs>
        $("div.foobar:visible").hide("fast");

        // Now show the one we're after.
        $div.show("fast");
    }

    // Make sure the link isn't followed.
    e.preventDefault();
});



You'll probably want to narrow down that div.foobar:visible selector, for example if they were in the form:

<div id="someID">
    <div id="divPippo"> ... </div>
    <div id="divPluto"> ... </div>
    ...
</div>


Rather than giving them each a particular class, you'd be better off using $("#someID > div:visible").hide("fast");


--
Best wishes,
Dave Cardwell.

Reply via email to