SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Dec 2010
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Set the bgcolor attribute value

    Hi,

    The following doesn't work:

    Code:
    <!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 ("width", "800"), it works with no problem! What am I missing?

    Any help is appreciated!
    Mike

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Location
    Dartmouth, MA, USA
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The bgcolor attribute is deprecated. Instead, use the background-color style attribute:

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

  3. #3
    SitePoint Addict
    Join Date
    Dec 2010
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bhawk90 View Post
    The bgcolor attribute is deprecated. Instead, use the background-color style attribute:

    Code JavaScript:
    <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.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Location
    Dartmouth, MA, USA
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •