Forums

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

Home Forums JavaScript Super simple jQuery accordion, help needed

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #176411
    tuleby
    Participant

    Hi!

    My knowledge of Javascript extends only to “cut& paste-coding” with existing jQuery examples etc. :)

    I can not get this simple accordion to work as I want. When clicking any H3 to expand the corresponding div with text, ALL of them are opened. I would of course only want them to open one at a time.

    See codepen:
    http://codepen.io/tuleby/pen/ijqHL

    Any simplifications that could be done to CSS and or jQuery would also be appreciated.

    Thanks in advance.

    #176413
    Paulie_D
    Member

    My JQuery is poor but I have this (so far)

    http://codepen.io/Paulie-D/pen/pkzse

    I’m still working on having the active div hide when clicked again..

    #176420
    Paulie_D
    Member

    Cracked it

    http://codepen.io/Paulie-D/pen/pkzse

    As I said. my JQ is pretty much cut and paste so perhaps this could all be tightened up…but it seems to work.

    That was fun…I learned something.

    #176421
    tuleby
    Participant

    Great! Thank you very much for this Paulie_D :)

    #176640
    Chromawoods
    Participant

    @Paulie_D it does not quite work as expected? If you expand one item and then click another one, that item does not expand. I made a fork of your fork and made a few modifications:
    http://codepen.io/chromawoods/pen/vEscu

    When we click an item, we must reference it with jQuery’s $(this). Also cached some selectors and utilized chaining for performance.

    #176641
    Paulie_D
    Member

    Odd…it was working when I posted but OK.

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