I'm very simply trying to add a class to the element .page-item-39 a
using Javascript but i'm getting the error "Uncaught TypeError: Cannot read property 'className' of undefined", what is the reason for this?
var menuItem = document.getElementsByClassName('page-item-39');
var menuLink = menuItem.firstChild;
console.log(menuLink);
menuLink.className += ' menu-item-active';
.menu-item-active {
border: 1px red solid;
}
<li class="page_item page-item-39">
<a>Classes</a>
</li>