Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

What is wrong with the javascript code?

Featured Replies

Im trying to get the menu open and close but it doesnt work. I did follow a tutorial on youtube..

Im a beginner and not good at javascript..

Here is the code for the whole site:

<!DOCTYPE html>
<html>
<head>
<title>My site</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<style>

* {
  box-sizing: border-box;
}

.row::after {
  content: "";
  clear: both;
  display: table;
}


body {
   margin: 0px;
   padding: 0px;
   color: black;
   text-align: center;
   background-color: white;
   background-image: url('');
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
  font-family: ;

}

h2 {
   font-size: 25px;
}

p {
   font-size: 20px;
}

.navbar {
  display: flex;
  justify-content:space-between;
  align-items: center;
  background-color: black;
  color: white;
}

.brand-title {
  font-size: 1.5rem;
  margin: .5rem;
}

.navbar-links ul {
  margin: 0;
  padding: 0;
  display: flex;
}

.navbar-links li {
  list-style: none;
}

.navbar-links li a {
  text-decoration: none;
  color: white;
  padding: 1rem;
  display: block;
}

.navbar-links li:hover {
  background-color: #555;
}

.toggle-button {
  position: absolute;
  top: .75rem;
  right: 1rem;
  display: none;
  flex-direction: column;
  justify-content: space-between;
  width: 30px;
  height: 21px;
}

.toggle-button .bar {
  height: 3px;
  width: 100%;
  background-color: white;
  border-radius: 10px;
}

@media (max-width: 700px) {
     .toggle-button {
          display: flex;
}

.navbar-links {
   display: none;
   width: 100%;
}

.navbar {
    flex-direction: column;
    align-items: flex-start;
}

.navbar-links ul {
    width: 100%;
    flex-direction: column;
}

.navbar-links li {
    text-align: center;
}
.navbar-links li a {
    padding: .5rem 1rem;
}

.navbar-links.active {
    display: flex;
}


</style>
</head>

<body>

<nav class="navbar">
<div class="brand-title">Brand Name</div>
<a href="#" class="toggle-button">
  <span class="bar"></span>
  <span class="bar"></span>
  <span class="bar"></span>
</a>
<div class="navbar-links">
<ul>
  <li><a href="#news">Kontakt</a></li>
  <li><a href="#contact">Nyheter</a></li>
  <li><a href="#about">Om</a></li>
</ul>
</div>
</nav>

<script>

const toggleButton = document.getElementsByClassName(’.toggle-button')[0]
const navbarLinks = document.getElementsByClassName(’.navbar-links')[0]

toggleButton.addEventListener('click', () => {
  navbarLinks.classlist.toggle('active)
})


</script>

 

</body>
</html>

 

 

Post the page to your hosting so we can see the menu.

And don’t get your code from YouTube. Most of it is junk.

Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.