JQuery code is very simple:
$('.nav-menu').on('click','li', function(){
$(this).addClass('selected').siblings().removeClass('selected');
upon click it adds class selected
to selected .nav-menu
element and removes that selected
class from all siblings.
Best and shortest way to do exact the same with pure JavaScript?
Possible duplicate is Not a solution
I need not just to add specific class. But also to remove that same class from all siblings of element.
Related HTML:
<ul id="tabnav" class="nav-menu">
<li class="tab selected"><a href="#">Element 1</a></li>
<li class="tab"><a href="#">Element 2</a></li>
<li class="tab"><a href="#">Element 3</a></li>
</ul>