When include js click event the anchor tag href doest work The HTML:
<li id="serviciosbtn"><a href="#servicios">SERVICIOS</a></li>
The JS
var servicios = document.getElementById("serviciosbtn");
servicios.addEventListener("click", function(e) {
nav.classList.add("hide-mobile");
e.preventDefault();
});
That actually apply the class but the a href is now not working
@ullfindsmit,是的,当我删除e.preventDefault()时它可以工作
e.preventDefault(); is the only reason Read the official documenation
Try removing the e.preventDefault(); it will behave normally
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.