# Technical Doc Page JavaScript Help

**URL:** <https://forum.freecodecamp.org/t/technical-doc-page-javascript-help/404088>\
**Category:** General\
**Created:** [June 16, 2020, 2:53am UTC](https://forum.freecodecamp.org/t/technical-doc-page-javascript-help/404088 "2020-06-16T02:53:41Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![codecory](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/codecory/32/146839_2.png) [@codecory](https://forum.freecodecamp.org/u/codecory)\
**Post date:** [June 16, 2020, 2:53am UTC](https://forum.freecodecamp.org/t/technical-doc-page-javascript-help/404088/1 "2020-06-16T02:53:41Z")

</div>

I used some light JavaScript for a menu button. It should show when the screen is below 755px. I keep getting it almost working, but it usually won’t close the menu when I click the button again. I tweaked the code and it stopped working, so I changed it back, but now it’s not working at all still. I’m going crazy! Please help me figure this out.  
I just want the menu in the top right to open when clicked, then close if you click anywhere on the screen.

> **[FCC - CSS Info Documentation](https://codepen.io/codecory/pen/XWmOpJX)**
>
> ...

---

<div class="post-metadata">

**Author:** ![ProgMan](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@ProgMan](https://forum.freecodecamp.org/u/ProgMan)\
**Post date:** [June 16, 2020, 4:12am UTC](https://forum.freecodecamp.org/t/technical-doc-page-javascript-help/404088/2 "2020-06-16T04:12:23Z")

</div>

Hi, your menuFunction() needs to find the navigation, not the menu. The navigation is the element that is hidden.

---

<div class="post-metadata">

**Author:** ![codecory](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/codecory/32/146839_2.png) [@codecory](https://forum.freecodecamp.org/u/codecory)\
**Post date:** [June 16, 2020, 4:31am UTC](https://forum.freecodecamp.org/t/technical-doc-page-javascript-help/404088/3 "2020-06-16T04:31:16Z")

</div>

Hah, I was getting so pissed I didn’t even notice I changed the wrong thing. Okay that fixed most, but it still won’t close when I click the icon again.

---

<div class="post-metadata">

**Author:** ![ProgMan](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@ProgMan](https://forum.freecodecamp.org/u/ProgMan)\
**Post date:** [June 16, 2020, 4:50am UTC](https://forum.freecodecamp.org/t/technical-doc-page-javascript-help/404088/4 "2020-06-16T04:50:55Z")

</div>

I would add and else to the end of your if statement. So:

if you find “hide”, remove it  
else add “hide”.

I don’t think you need the show class.  
Also, I saw 2 instances of the class .hide in your css.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![codecory](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/codecory/32/146839_2.png) [@codecory](https://forum.freecodecamp.org/u/codecory)\
**Post date:** [June 16, 2020, 9:31pm UTC](https://forum.freecodecamp.org/t/technical-doc-page-javascript-help/404088/5 "2020-06-16T21:31:09Z")

</div>

Idk what I was thinking with the show class, thanks for pointing that out haha.  
As for the 2 instances of .hide, that is so that when the screen is larger .hide has block display, but none display when smaller cause I need the larger screen to always show the menu. The 2nd one is under the media query.  
The code originally had the else statement, and it worked, but once I added the code to hide when anything is clicked, that broke. So, I can click anywhere to close it, except the icon itself.

---

<div class="post-metadata">

**Author:** ![ProgMan](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@ProgMan](https://forum.freecodecamp.org/u/ProgMan)\
**Post date:** [June 16, 2020, 11:25pm UTC](https://forum.freecodecamp.org/t/technical-doc-page-javascript-help/404088/6 "2020-06-16T23:25:27Z")

</div>

I don’t know. I did get the menu to show and hide by clicking the button, but I commented out the window.addEventListener function and added this to the if statement:

else if (!d.classList.contains(“hide”)) {  
d.classList.add(“hide”);  
}

---

<div class="post-metadata">

**Author:** ![codecory](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/codecory/32/146839_2.png) [@codecory](https://forum.freecodecamp.org/u/codecory)\
**Post date:** [June 17, 2020, 7:34pm UTC](https://forum.freecodecamp.org/t/technical-doc-page-javascript-help/404088/7 "2020-06-17T19:34:05Z")

</div>

Yea, doing that will make it work, but then if you click elsewhere on the page it won’t close, and it won’t close if you click on a section to go to. So, that is my predicament.

---

<div class="post-metadata">

**Author:** ![ProgMan](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@ProgMan](https://forum.freecodecamp.org/u/ProgMan)\
**Post date:** [June 17, 2020, 11:00pm UTC](https://forum.freecodecamp.org/t/technical-doc-page-javascript-help/404088/8 "2020-06-17T23:00:26Z")

</div>

I was playing around with it and see there does not seem to be a quick fix. I did some searching and found something that might help.  
[Detecting a Click Outside an Element in JavaScript](https://www.blustemy.io/detecting-a-click-outside-an-element-in-javascript/)

---

<div class="post-metadata">

**Author:** ![codecory](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/codecory/32/146839_2.png) [@codecory](https://forum.freecodecamp.org/u/codecory)\
**Post date:** [July 17, 2020, 3:49pm UTC](https://forum.freecodecamp.org/t/technical-doc-page-javascript-help/404088/9 "2020-07-17T15:49:01Z")

</div>

Now that the forum is back up, thanks for your help! I was eventually able to figure out how to re-work the code to get it working exactly how I wanted.

---

<div class="post-metadata">

**Author:** ![ProgMan](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@ProgMan](https://forum.freecodecamp.org/u/ProgMan)\
**Post date:** [July 25, 2020, 2:01pm UTC](https://forum.freecodecamp.org/t/technical-doc-page-javascript-help/404088/10 "2020-07-25T14:01:40Z")

</div>

Hey, that mobile menu is working great now! Nice job.

---

<div class="post-metadata">

**Author:** ![codecory](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/codecory/32/146839_2.png) [@codecory](https://forum.freecodecamp.org/u/codecory)\
**Post date:** [July 26, 2020, 6:19pm UTC](https://forum.freecodecamp.org/t/technical-doc-page-javascript-help/404088/11 "2020-07-26T18:19:36Z")

</div>

Thanks! Yea I realized the icon was in the way and needed to become part of the code. Glad I got it going cause now all my pages function great!

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:45pm UTC](https://forum.freecodecamp.org/t/technical-doc-page-javascript-help/404088/12 "2021-06-01T18:45:25Z")

</div>

Closed on June 1, 2021, 6:45pm UTC


