I have the following menu and I want to add a class 'active' to the last clicked link. Using native javascript not with JQuery.
Firstly, I'm removing active from all links then trying to add 'active' to clicked link
Here's what I'm trying but simply does nothing:
<a href="#" class="menu active" onclick="changeClass()">test 1</a>
<a href="#" class="menu" onclick="changeClass()">test 2</a>
<a href="#" class="menu" onclick="changeClass()">test 3</a>
function changeClass() {
document.getElementsByClassName('menu').classList.remove('active');
this.className('menu active');
}
Here's a fiddle to have a look at but not if jsfiddle is working correctly