# adding onclick to module

**URL:** <https://community.hubspot.com/t/adding-onclick-to-module/57256>\
**Category:** CMS Development\
**Tags:** professional\
**Created:** [May 18, 2022, 9:56pm UTC](https://community.hubspot.com/t/adding-onclick-to-module/57256 "2022-05-18T21:56:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DNeubauer](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@DNeubauer](https://community.hubspot.com/u/DNeubauer)\
**Post date:** [May 18, 2022, 9:56pm UTC](https://community.hubspot.com/t/adding-onclick-to-module/57256/1 "2022-05-18T21:56:04Z")

</div>

Trying to create a hamburger menu but the HTML is not reading my onclick. This is my button:

\<button  
class=“dropbtn-mobile”  
onclick=“toggleMenu()”\>

And my js:

function toggleMenu() {  
console.log(‘hello’);  
var menuBox = document.getElementById(‘dropdown-content-mobile’);  
if(dropdown-content-mobile.style.display == “block”) { // if is menuBox displayed, hide it  
dropdown-content-mobile.style.display = “none”;  
}  
else { // if is menuBox hidden, display it  
dropdown-content-mobile.style.display = “block”;  
}  
}

It says my function is not defined.

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [May 19, 2022, 2:44pm UTC](https://community.hubspot.com/t/adding-onclick-to-module/57256/2 "2022-05-19T14:44:18Z")

</div>

@DNeubauer

I would check out that if statement. instead of using your declared variable **menuBox** , you are using an undefined variable **dropdown-content-mobile** which appears to be a css ID.

@Oezcan , what do you think?

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [May 19, 2022, 3:09pm UTC](https://community.hubspot.com/t/adding-onclick-to-module/57256/3 "2022-05-19T15:09:01Z")

</div>

Hi @DNeubauer,

seems like a pretty “complicated” function for just a toggle effect.

Try this(don’t forget to load jQuery before this code):

```lia-code-sample
$( ".dropbtn-mobile" ).click(function() {
$( ".dropdown-content.mobile" ).slideToggle( "slow", function());
});

```

hope this helps,

best,

Anton

---

@dennisedson - jumping in since @Oezcan is on vacation 😁

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [May 19, 2022, 3:11pm UTC](https://community.hubspot.com/t/adding-onclick-to-module/57256/4 "2022-05-19T15:11:37Z")

</div>

Let him know that he is not being paid while on this vacation 🙃
