Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript .slideToggle one div a time

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #36978
    Rugg
    Participant

    Hello All!

    I am having some problems configuring the jQuery .slideToggle to only open one div per click. I have two links – each link toggles open/close a separate div – however if one div is open, and the link to toggle the second div is clicked, they both remain open and stacked on each other.

    My goal is to configure this to only allow one div to be toggled open at a time. If the first div is open—clicking the link to toggle the second will close the open div.
    It seems to be something quite simple, but I can’t seem to wrap my hands on it. Any help is much appreciated. Thank you.

    Here is a jsFiddle Link: http://jsfiddle.net/u7Y2r/28/

    #98150

    How about this: http://jsfiddle.net/joshnh/SCKhf/

    I have removed the duplication that you have going on in your code, so that way it doesn’t matter how many list items you have; the one function will work. I’d love for someone who knows more about jQuery to step in and suggest improvements.

    #98153

    Right, I have updated the above link :)

    #98157

    @NSR Of course, sorry. Here it is with that taken care of: http://jsfiddle.net/joshnh/SCKhf/

    #98159

    Not without having to rewrite the jQuery for each anchor/div pair (as you originally had). I would try and use positioning to make my version work.

    #98163

    Good point @karlpcrowley, I have updated the fiddle to do just that: http://jsfiddle.net/joshnh/SCKhf/

    #121176
    adavis
    Participant

    How would one accomplish this with divs instead of lists?
    [Website in progress](http://www.lindseysoftware.com/SoftwarePortal/index.html “Website in progress”)

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.