I have three divs with the same class name that I want to alter the height and color of using JavaScript. My code is breaking, not sure why. I've looked at answers to similar problems on here and my code seems to be the same as the solutions.
Any idea on where my code is breaking and how to fix it ?
<HTML>
<head></head>
<body>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<script>
function altSize() {
var bar = document.getElementsByClassName("bar");
bar.style.height = 200px;
bar.style.background = 'red';
}
altSize();
</script>
</body>
</HTML>
.bar{height: 200px;}why not this?