Well I have a menu with li tags and it has an a element has a child for navigation and everything works fine , the problem is that I want to remove all the elements, which has the class seleccionado and add only the li on which I'm clicking. I tried .remove to remove the class. It doesn't work, so is there any other option??
The function removes first all elements with that class and after that it only adds the class to the li, which has been clicked.
clicked(event) {
var el = document.getElementsByClassName("detectar");
el.classList.remove("seleccionado");
if(window.location.pathname){
event.path[3].classList.add("seleccionado");
}
}
you should avoid using javascript DOM manipulation in Angular. Check my example below. Angular is very powerfull and does not need to use traditional DOM manipulation
this.showMyClass = true;
clicked(event){
this.showMyClass = false;
}
in Html
<div [ngClass]="{'myClass': showMyClass}"> </div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With