Set the bgcolor attribute value

Hi,

The following doesn’t work:

<!DOCTYPE HTML>
<title>Test</title>
<embed id="foo" src="http://www.w3schools.com/media/bookmark.swf" width="400" height="40" type="application/x-shockwave-flash" />

<script type="text/javascript">
document.getElementById("foo").setAttribute("bgcolor", "#00FF00");
</script>

But if you change setAttribute to I[/I], it works with no problem! What am I missing?

Any help is appreciated!
Mike

The bgcolor attribute is deprecated. Instead, use the background-color style attribute:


<script type="text/javascript">
  document.getElementById("foo").style.backgroundColor = "#00FF00";
</script>

Thanks for the answer, but they are two different things. To see what I mean please try adding bgcolor=“#00FF00” to the embed code and compare it with changing the style background color.

The only way I was able to change the background color was by specifying the bgcolor as an attribute within the tag, rather than using JavaScript to set it. Also, if that’s your entire code, I would include html, head and body tags on the page.