Tuesday, March 23, 2010

Changing td (or table) background image to another from JavaScript

 <html>
  <head>
    <style>
      #Good {
        background-repeat: no-repeat;
        background-position: center center;
        background-image: url(images/image40.gif);
      }
    </style>
    <script>
      <!--
      function changeImage() {
        newImage = "url(images/image41.gif)";
        document.getElementById('Good').style.backgroundIm  age = newImage;
      }
      //-->
    </script>
  </head>
  <body>
    <table>
      <tr>
        <td id="Good"><br>Hopefully there is a nice picture behind me :P</td>
      </tr>
      <tr>
        <td><button onClick="changeImage()">Click Me</button><td>
    </table>
  </body>
</html>

No comments:

Post a Comment