Change the background image in a table cell

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jim

    Change the background image in a table cell

    How can I use JavaScript to change a background image in a table cell?

    Here's the code for the cell

    <td width="338" valign="top" background="../images/
    LEC_Q1.jpg"><di v align="right"></div></td>

    You can see that the background is set to the image LEC_Q1.jpg. I
    want to change the image LEC_Q1.jpg to LEC_Q1_faded.jp g after a user
    clicks a button and the only way I can figure out to do it is by using
    JavaScript somehow.
  • Thomas 'PointedEars' Lahn

    #2
    Re: Change the background image in a table cell

    Jim wrote:
    How can I use JavaScript to change a background image in a table cell?
    >
    Here's the code for the cell
    >
    <td width="338" valign="top" background="../images/
    LEC_Q1.jpg"><di v align="right"></div></td>
    >
    You can see that the background is set to the image LEC_Q1.jpg. I
    want to change the image LEC_Q1.jpg to LEC_Q1_faded.jp g after a user
    clicks a button and the only way I can figure out to do it is by using
    JavaScript somehow.
    1. refToTD.backgro und = "...";

    2. You want to use CSS and

    refToTD.style.b ackgroundImage = "url(...)";

    instead.

    3. You don't want to use an empty table cell here, and probably also not
    tables in the first place, but a properly positioned `img' element
    instead. A table is a table is a table. [psf 3.8]


    PointedEars
    --
    var bugRiddenCrashP ronePieceOfJunk = (
    navigator.userA gent.indexOf('M SIE 5') != -1
    && navigator.userA gent.indexOf('M ac') != -1
    ) // Plone, register_functi on.js:16

    Comment

    • SAM

      #3
      Re: Change the background image in a table cell

      Jim a écrit :
      How can I use JavaScript to change a background image in a table cell?
      >
      Here's the code for the cell
      >
      <td width="338" valign="top" background="../images/
      LEC_Q1.jpg"><di v align="right"></div></td>
      >
      You can see that the background is set to the image LEC_Q1.jpg. I
      want to change the image LEC_Q1.jpg to LEC_Q1_faded.jp g after a user
      clicks a button
      <td width="338" valign="top"
      style="backgrou nd:url(../images/LEC_Q1.jpg)no-repeat center center"
      onmouseover="th is.style.backgr oundImage='url( ../images/LEC_Q1_faded.jp g)';"
      onmouseout="thi s.style.backgro undImage='url(. ./images/LEC_Q1.jpg)';">



      <td id="td_1" width="338" valign="top"
      style="backgrou nd:url(../images/LEC_Q1.jpg)no-repeat center center">

      <button
      onclick="docume nt.getElementBy Id('td_1').styl e.backgroundIma ge='url(../images/LEC_Q1_faded.jp g)';">
      change td_1's image</button>

      --
      sm

      Comment

      Working...