Q:

JS Adding a class to a class

I am trying to get this very basic code to run, where I add a class to the selected elements.
https://jsfiddle.net/wm27ch2p/1/

document.getElementsByClassName("liHome")[0].classname += ' active';
document.getElementsByClassName("aHome")[0].classname += ' active';
<li class="liHome"><a class="aHome" href="#yellowBar">Home</a></li>

EDIT: Thank you for pointing out the typo, in addition to this question is there any way I can add this class name to all of the elements with liHome or aHome class, instead of just [0].

A:

className is camel-cased:

document.getElementsByClassName("liHome")[0].className += ' active';
document.getElementsByClassName("aHome")[0].className += ' active';
<li class="liHome"><a class="aHome" href="#yellowBar">Home</a></li>

Alternately you can use use classList.

document.getElementsByClassName("liHome")[0].classList.add('active');
document.getElementsByClassName("aHome")[0].classList.add('active');
<li class="liHome"><a class="aHome" href="#yellowBar">Home</a></li>

