jorgenfi
05-14-2009, 11:34 PM
I try to learn how to change css background-properties via javascript, but i don't even get this simple one to work. What is wrong?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function changeBackground() {
document.getElementsByTagName("body").style.background="#00FF00";
}
</script>
</head>
<body>
blablabla<br>
<input type="button" onclick="changeBackground()" value="Change color" />
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function changeBackground() {
document.getElementsByTagName("body").style.background="#00FF00";
}
</script>
</head>
<body>
blablabla<br>
<input type="button" onclick="changeBackground()" value="Change color" />
</body>
</html>