I am trying to change the color of this text to green using JavaScript, but I get a warning about it being a bad object and the script crashes.
<html>
<head>
<style>
b {
color: #0000FF;
}
</style>
<script>
function resizea() {
var a = document.getElementsByTagName("b");
a.style.color = "#00FF00";
}
</script>
</head>
<body onload="resizea()">
<b>I am blue</b>
</body>
</html>
since
getElementsByTagName("b")return a collection of elements, you need to get the first one:Note the index between brackets
[0]