MD.ALIMUL Alrazy
MD.ALIMUL Alrazy

Reputation: 330

menu is not showing onclick function is not working properly

My onclick function is not working properly. When I click the menubar mobile menu it just shows like a flash. It's not stable. When I click the menu bar it adds classes but removes them suddenly. What's the problem with the click event, I don't understand. Please suggest to me how I could manage this.

Here is my code:

.shown {
  display: block !important;
}

.mobile-menu {
  position: absolute;
  z-index: 999;
  height: 100vh;
  width: 100%;
  background: #e4e3e3;
  top: 0;
  left: 0;
  line-height: 2;
  display: none;
  overflow: hidden;
  z-index: 9999;
}

.mobile-menu .menu-list {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 70vh;
  width: 100%;
}

.mobile-menu .menu-list .menu-item {
  width: 100%;
  text-align: center;
}

.mobile-menu .menu-list .menu-item .menu-link {
  font-size: 22px !important;
  text-decoration: none;
  cursor: pointer;
  font-weight: 700;
  display: block;
  transition: all .5s ease;
  color: #00A139;
}

.mobile-menu .menu-list .menu-item .menu-link:hover {
  color: #ffffff;
  background: #00A139;
}
<!-- mobile menu -->
<div id="menus" class="mobile-menu">
  <ul class="menu-list">
    <li class="menu-item">
      <a class="menu-link" href="products.html">PRODUCTS</a>
    </li>
    <li class="menu-item">
      <a class="menu-link" href="sustainability.html">SUSTAINABILITY</a>
    </li>
    <li class="menu-item">
      <a class="menu-link" href="compliance.html">COMPLIANCE</a>
    </li>
    <li class="menu-item">
      <a class="menu-link" href="investors.html">INVESTORS</a>
    </li>
    <li class="menu-item">
      <a class="menu-link" href="about.html">ABOUT</a>
    </li>
    <li class="menu-item">
      <a class="menu-link" href="contact.html">CONTACT</a>
    </li>
  </ul>
</div>
<!-- End mobile menu -->

<a href="" id="myBtn" class="humburger d-lg-none d-md-none">
    aaaaaa
</a>

Upvotes: 0

Views: 186

Answers (1)

Toolbox
Toolbox

Reputation: 2483

Given the code you provide, you are missing:

  • in HTML: onclick() connected to to a div or button.
  • in javascript: a javascript that triggers a created function (where function is connected to the HTML onclick).

Below you find a basic but functional working example:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

    <body>

    <button type="button" name="button" onclick="changeBackground()">Change background</button>

    <script type="text/javascript">
        function changeBackground() {
        document.body.style.background = "black";
        }
    </script>

    </body>

</html>

Upvotes: 2

Related Questions