double click issue to trigger a function

Discussion in 'jQuery' started by londonstyler, Feb 8, 2011.

  1. #1
    Hi,

    I want to include a number of boxes on a page that reveal content when clicked. I seem to have these working ok, although when one box is open, i have to click twice on another to get it to work.

    You can view this in action here:

    http://www.dave-tyler.co.uk/showcasetest4.html

    Is there a way i can stop this from happening?

    Many thanks for your help
     
    londonstyler, Feb 8, 2011 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yeah, use slideToggle. Replace that huge if..else block with this:
    
    $("#show a").click(function () { $(this).next().slideToggle(); });
    
    Code (markup):
    Shouldn't really use next, but I had no luck selecting the div itself. Think I need to brush up on selectors :)
     
    Last edited: Feb 12, 2011
    Cash Nebula, Feb 12, 2011 IP
  3. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ok, this is probably better to use:
    
    $("#show a").click(function () { $(this).siblings("div").slideToggle(); });
    
    Code (markup):
     
    Cash Nebula, Feb 12, 2011 IP