Jump to content

Why this function is not working?


m.s_shohan

Recommended Posts

Here is a code.

HTML

			<div class= "navbar-container">
				<ul>
					<li onclick= "active(notAct)"><a href= "#home" class= "border-bottom">Home</a></li>
					<li onclick= "active(notAct)"><a href= "#" class= "border-bottom">Portfolio</a></li>
					<li onclick= "active(notAct)"><a href= "#" class= "border-bottom">Gallery</a></li>
					<li onclick= "active(notAct)"><a href= "#" class= "border-bottom">Services</a></li>
					<li onclick= "active(notAct)"><a href= "#" class= "border-bottom">Testimonials</a></li>
					<li onclick= "active(notAct)"><a href= "#" class= "border-bottom">Contact Now</a></li>
				</ul>
			</div> 

CSS

.navbar-container {
	position: absolute;
	right: 7%;
	top: 0;
	margin: 0;
	padding: 0;
	height: 100%;
}
.navbar-container ul {
	margin: 0;
	padding: 0;
	list-style: none;
	float: right;
}
.navbar-container ul li {
	display: inline-block;
	font-family: 'roboto slab',merriweather,Montserrat;
}
.navbar-container ul li a {
	position: relative;
	padding: 14px 10px;
	display: block;
	font-size: 1em;
	color: white;
	text-align: center;
	text-decoration: none;
}
.not-active {
	pointer-events: none;
	cursor: default;
	animation-play-state: paused;
} 

JavaScript

function active(notAct) {
	'use strict';
	var i, category;
	category = document.getElementsByClassName("border-bottom");
	for (i = 0; i < category.length; i++) {
		category[i].className = category[i].className.replace(" not-active", "");
	}
	notAct.currentTarget.className += " not-active";
} 

I want that when a category item is clicked, it will be replaced with not-active class and the menu will be disabled. But this doesn't work properly. Can you please tell me where is problem in my code? Thank you in advance.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...