2
I got the following nav
:
<nav>
<ul>
<li><a href="">1</a></li>
<li><a href="">2</a></li>
<li><a href="">3</a></li>
</ul>
</nav>
and the Javascript code:
var linkElement = document.querySelector('nav a');
linkElement.classList.add('blue');
But in doing so it adds the class only in the first element.
If I do so:
var linkElement = document.querySelectorAll('li a');
or
var linkElement = document.getElementsByTagName('a');
It returns me the following error:
Uncaught Typeerror: Cannot read Property 'add' of Undefined
How do I add the class to all links ?
Got it, this returning Array is Nodelist? I read in the documentation, but as I’m starting out, I couldn’t quite understand that part. Even, problem solved.
– oricardo_