SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2014
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    can we get red color background using document.bgColor="rgb(255,0,0)"; line?

    Code:
    <!DOCTYPE html>
    <html>
    <body>
    <script>
    
     function red()
    {
     document.bgColor="#FF0000";
    }
    
    
     function red1()
    {
     document.bgColor="red";
    }
    
     function red2()
    {
     document.bgColor="rgb(255,0,0)";
    }
    
    </script>
    
    <button type="button" onclick=" red(); ">RED background</button>
    <button type="button" onclick=" red1(); ">RED background</button>
    <button type="button" onclick=" red2(); ">RED background</button>
    
    </body>
    </html>
    Last edited by Pullo; Jun 29, 2014 at 07:32. Reason: Code tags

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,154
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Instead of "bgColor" try "background-color" and "backgroundColor" with "style".

  3. #3
    SitePoint Member
    Join Date
    Jun 2014
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi sir,
    inside a <script> and inside a function, background-color using style doesnt works...please help me find a solution.
    <script>

    style = "document.background-color: rgb(255,0,0);"> <p>inside a style function tag does not works </p>
    </div>
    </script>

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    In the HTML (attached to a tag)

    style="background-color:rgb(255,0,0);"


    In JavaScript (attached to the node you want it to apply to)

    style.backgroundColor = 'rgb(255,0,0)';
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


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
  •