Home > database >  The code doesnt work. The toggle is supposed to work but it doesnt invoke the class. Developer optio
The code doesnt work. The toggle is supposed to work but it doesnt invoke the class. Developer optio

Time:10-23

**This code doesnt work I have included all the js files into the code but still the login toggle didnt work. Even developer options doesnt give us any clues on this.

$('.navbar-toggle').click(() => {

  $('.navbartab').toggleclass('.navbar-tab--open');

})
.logoimage {
  width: 8rem;
  height: 5rem;
  filter: drop-shadow(12px 14px 10px grey);
  position: absolute;
  top: .5rem;
  left: 3rem;
}

.logo {
  font-family: font-family: 'Unkempt', cursive;
  font-weight: 200;
  font-size: 40px;
  margin-left: 12rem;
  position: relative;
}

.navbartab {
  background-color: tomato;
  position: absolute;
  top: 100%;
  right: 0%;
  height: 0px;
  overflow: hidden;
}

.container-fluid {
  background: #ee5d5d;
  color: rgb(255, 175, 71);
  padding: 1.4em 0;
  position: relative;
}

.navbartab ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.navbartab a {
  color: yellow;
  display: block;
  padding: 2em 6em;
  text-decoration: thistle;
  text-transform: uppercase;
}

.navbartab a:hover,
.navbartab a:focus {
  background-color: red;
  color: rgb(71, 255, 117);
}

.navbartab Li:last-child {
  border-bottom: none;
}

.navbartab Li {
  border-bottom: 2px solid coral
}

.navbar-toggle {
  position: absolute;
  background: #ee5d5d;
  padding: 2rem;
  right: .75rem;
  top: .75rem;
  cursor: pointer;
}

.menu-toggle,
.menu-toggle::before,
.menu-toggle::after {
  content: '';
  display: block;
  background: rgb(211, 219, 219);
  height: 3px;
  width: 2em;
  border-radius: 3px;
}

.menu-toggle::before {
  transform: translateY(-6px);
}

.menu-toggle::after {
  transform: translateY(3px);
}

.navbar-tab--open {
  height: auto;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>

<body>

  <header>
    <div class="container-fluid">


      <h1 class="logo">FamilyShop</h1>
      <img class="logoimage" src="su-30mki-iaf-fb.jpg">

      <nav class="navbartab">
        <ul>
          <li> <a href="">Home</a></li>
          <li> <a href="">contact</a></li>
          <li> <a href="">career</a></li>
          <li> <a href="">aboutus</a></li>
          <li> <a href="">feedback</a></li>


        </ul>

      </nav>

      <div class="navbar-toggle">
        <div class="menu-toggle"></div>

      </div>

    </div>
  </header>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

  1. you should attach click handler when jQuery is loaded and dom is ready i.e. $(function(){ ... here ... });.
  2. toggleclass is actually toggleClass.
  3. The argument of toggleClass is the class name navbar-tab--open but not the class selector .navbar-tab--open, so it is toggleClass('navbar-tab--open').

$(function(){
  $('.navbar-toggle').click(() => {
    $('.navbartab').toggleClass('navbar-tab--open');
  })
});
.logoimage {
  width: 8rem;
  height: 5rem;
  filter: drop-shadow(12px 14px 10px grey);
  position: absolute;
  top: .5rem;
  left: 3rem;
}

.logo {
  font-family: font-family: 'Unkempt', cursive;
  font-weight: 200;
  font-size: 40px;
  margin-left: 12rem;
  position: relative;
}

.navbartab {
  background-color: tomato;
  position: absolute;
  top: 100%;
  right: 0%;
  height: 0px;
  overflow: hidden;
}

.navbar-tab--open {
  height: auto;
  z-index: 10000
}

.container-fluid {
  background: #ee5d5d;
  color: rgb(255, 175, 71);
  padding: 1.4em 0;
  position: relative;
}

.navbartab ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.navbartab a {
  color: yellow;
  display: block;
  padding: 2em 6em;
  text-decoration: thistle;
  text-transform: uppercase;
}

.navbartab a:hover,
.navbartab a:focus {
  background-color: red;
  color: rgb(71, 255, 117);
}

.navbartab Li:last-child {
  border-bottom: none;
}

.navbartab Li {
  border-bottom: 2px solid coral
}

.navbar-toggle {
  position: absolute;
  background: #ee5d5d;
  padding: 2rem;
  right: .75rem;
  top: .75rem;
  cursor: pointer;
}

.menu-toggle,
.menu-toggle::before,
.menu-toggle::after {
  content: '';
  display: block;
  background: rgb(211, 219, 219);
  height: 3px;
  width: 2em;
  border-radius: 3px;
}

.menu-toggle::before {
  transform: translateY(-6px);
}

.menu-toggle::after {
  transform: translateY(3px);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>

<body>
  <header>
    <div class="container-fluid">
    <h1 class="logo">FamilyShop</h1>
      <img class="logoimage" src="su-30mki-iaf-fb.jpg">
      <nav class="navbartab">
        <ul>
          <li> <a href="">Home</a></li>
          <li> <a href="">contact</a></li>
          <li> <a href="">career</a></li>
          <li> <a href="">aboutus</a></li>
          <li> <a href="">feedback</a></li>
        </ul>
      </nav>
      <div class="navbar-toggle">
        <div class="menu-toggle"></div>
      </div>
    </div>
  </header>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related