Reputation: 71
This is a simple representation of what I'm facing
var box=document.getElementsByClassName('foo')
box.classList.add('things')
.foo{
height: 50px;
width: 50px;
background-color: aqua;
border: 1px solid royalblue;
}
.things{
border-radius: 50%;
}
<body>
<div class="foo"></div>
</body>
Javascript console always returns these. Uncaught TypeError: Cannot read property 'add' of undefined Is there anything I'm missing?
Upvotes: 0
Views: 41
Reputation: 28434
getElementsByClassName
returns a list, so you need to specify the index
as follows:
var box=document.getElementsByClassName('foo')[0];
Upvotes: 2