The easiest solution here is to use document.querySelector
. Bear in mind that I am assuming that you only have one element that will match that CSS selector.
document.querySelector('.navbar-brand > a').style.color = 'black';
If it's a case that you're expecting to change multiple elements which match to that CSS selector you've used then you should use document.querySelectorAll
.
const uiElements = document.querySelectorAll('.navbar-brand > a');
uiElements.forEach(uiElement => {
uiElement.style.color = 'black';
});
However, going back to your original question, if you absolutely must use document.getElementsByClassName
then the solution (again for multiple elements) would be as follows:
const navbarElements = document.getElementsByClassName('navbar-brand');
navbarElements.forEach(uiElement => {
uiElement.querySelector('a').style.color = 'black';
});
Hope this helps!