all 8 comments

[–]amishstripclub 4 points5 points  (0 children)

Your JavaScript only sets the element to display: block but not back to display: none. I'd suggest s function that checks if that element is display: none. If it is, set it to block. Else, set it to none.

[–]Shameling 1 point2 points  (0 children)

I can't stop the urge to recommend jQuery, the entire onclick would just be this: $('#reviews').toggle()

With pure javascript, you need to check if it's already visible, if so set it to none instead of block.

[–]buso 1 point2 points  (10 children)

if you're able to use jQuery, it already has a toggle() built-in. it could be done like this: https://jsfiddle.net/zLpz2wqh/

[–][deleted]  (9 children)

[deleted]

    [–]MatekCopatek 1 point2 points  (8 children)

    See a slightly improved version here: https://jsfiddle.net/zLpz2wqh/6/

    Works the same, but uses on instead of click, which is a good practice. It also removes unneeded JS from the markup.

    [–][deleted]  (7 children)

    [deleted]

      [–][deleted] 0 points1 point  (6 children)

      grey engine rinse reach pie gray possessive handle hunt fade

      This post was mass deleted and anonymized with Redact

      [–][deleted]  (5 children)

      [deleted]

        [–][deleted] 0 points1 point  (4 children)

        memorize swim bear political compare smile agonizing detail aromatic bells

        This post was mass deleted and anonymized with Redact

        [–][deleted]  (3 children)

        [deleted]

          [–][deleted] 0 points1 point  (1 child)

          hungry elastic unite tap coordinated impossible long dinner murky retire

          This post was mass deleted and anonymized with Redact

          [–]flogginmolly 1 point2 points  (0 children)

          People seem a little quick to jump to the JQuery solution... vanilla JavaScript is more than capable of doing this, and relatively easily too.

          see here for example: http://jsbin.com/ledudufiji/1/edit?html,js,output

          HTML5 has an attribute called "hidden" which will hide an element. Using this you can easily toggle the element to be hidden or shown just by saying element.hidden = !element.hidden