toptomato;1218963 wrote:just wondering why my syntax isn't working here..
this doesn't work...
function setBg() {
el = document.getElementsByTagName('body');
el.style.backgroundColor = "#f9f363";
}
but this does.....
function setBg() {
document.body.style.backgroundColor = "#f9f363";
}
getElementsByTagName() returns an array, not an individual value.
Needs to be accessed like an array element.
See:
<script type="text/javascript">
function setBG() {
el = document.getElementsByTagName('body');
el[0].style.backgroundColor = "#00f363";
}
function SETbg() {
document.body.style.backgroundColor = "#f9f363";
}
</script>
<body>
<button onclick="setBG()">Tag BG set</button>
<button onclick="SETbg()">DOM BG set</button>
</body>