m.s_shohan Posted November 10, 2016 Share Posted November 10, 2016 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 More sharing options...
justsomeguy Posted November 10, 2016 Share Posted November 10, 2016 What's the notAct variable that you have in the onclick attribute? Link to comment Share on other sites More sharing options...
davej Posted November 10, 2016 Share Posted November 10, 2016 For the inline Javascript approach you need to actually use the keyword 'event' as the parameter. See... http://www.w3schools.com/jsref/tryit.asp?filename=try_dom_event_currenttarget Also you should be using the browser console to see Javascript errors. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now