Reputation: 31
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");
}
}
Upvotes: 3
Views: 16062
Reputation: 30663
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>
Upvotes: 4