Having trouble adding a classname to my JavaScript code which looks like so:
var a = document.querySelectorAll('.nav-tabs');
for(var i=0 ; i<a.length; i++){
a[i].addEventListener('click',function(){
a[i].classList.add("active");
});
}
An error message pops up saying Uncaught TypeError: Cannot set property 'className' of undefined and this is how my HTML appears:
<nav>
<div class="container" id="container">
<ul class="nav nav-tabs">
<li role="presentation"><a href="#">a</a></li>
<li role="presentation"><a href="#">b</a></li>
<li role="presentation"><a href="#">c</a></li>
</ul>
</div>
</nav>
I would greatly appreciate it if someone could assist me in resolving this issue. Thank you very much.