I added the click event to all buttons but my intention is to have the event occur on a button inorder to extract the buttons text(btnText).
I have tried the .removeClass() and .addClass() methods but its still not working as I expected.
<ul>
<li><button>Dog</button></li>
<li><button>Cat</button></li>
<li><button>Moose</button></li>
</ul>
$('button').click(() => {
$('button').removeClass("selected");
$(this).addClass("selected");
let btnText = $(this).text(); *// expected result(Dog|Cat|Moose)*
console.log(btnText); *// printed result (DogCatMoose)*
}); // end click