Change Background JS - JavaScript Help

Discussion in 'HTML & Website Design' started by ChristopherLeeMaher.Com, May 22, 2010.

  1. #1
    ChristopherLeeMaher.Com, May 22, 2010 IP
  2. hdewantara

    hdewantara Well-Known Member

    Messages:
    541
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #2
    Something like this?

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    
    <head>
    
    <link rel="stylesheet" type="text/css" href="1.css" />
    <style type"text/css">
      #wrapper{
        width: 100px;
        height: 100px;
        margin: 0px auto;
        background-color: cyan;
      }
    </style>
    
    <script type="text/javascript">
      function changef(a){
        var
          b = document.getElementsByTagName("link")[0];
        if (b.rel == "stylesheet"){
          b.href = a;
        }
      }  
    </script>
    
    </head>
    
    <body>
      <div id="wrapper" class="class1">
        hello dolly
        <input type="button" value="1.css" onclick="changef(this.value)">
        <input type="button" value="2.css" onclick="changef(this.value)">
        <input type="button" value="3.css" onclick="changef(this.value)">
      </div>
    </body>
    
    </html>
    HTML:
    where 1.css contains:
    .class1{
    	color:red;
    }
    Code (markup):
    and 2.css contains:
    .class1{
    	color:green;
    }
    Code (markup):
    & so on..
     
    Last edited: May 23, 2010
    hdewantara, May 23, 2010 IP
  3. ChristopherLeeMaher.Com

    ChristopherLeeMaher.Com Guest

    Messages:
    185
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey, man thanks this really helped me out
    Chris,
     
    ChristopherLeeMaher.Com, May 25, 2010 IP