I'm currently using Angular CLI and I have a menu list that I want to customize. Specifically, I want to change the background color of the <li>
element when it is clicked. I am passing an id
to the changeColor()
function, but unfortunately, I am encountering an issue where menuButton is returned as null. Can someone please assist me with this problem?
.html
<ul>
<li id="menu_btn" (click)="changeColor()" >
</li>
<li id="menu_btn" (click)="changeColor()">
</li>
<ul>
.ts:
changeColor() {
let menuButton = document.getElementById("menu_btn");
menuButton.style.backgroundColor = '#816587';
}