473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Change the background image in a table cell

Jim
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"><div 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.jpg after a user
clicks a button and the only way I can figure out to do it is by using
JavaScript somehow.
Jul 23 '08 #1
2 3782
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"><div 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.jpg after a user
clicks a button and the only way I can figure out to do it is by using
JavaScript somehow.
1. refToTD.background = "...";

2. You want to use CSS and

refToTD.style.backgroundImage = "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 bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Jul 23 '08 #2
SAM
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"><div 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.jpg after a user
clicks a button
<td width="338" valign="top"
style="background:url(../images/LEC_Q1.jpg)no-repeat center center"
onmouseover="this.style.backgroundImage='url(../images/LEC_Q1_faded.jpg)';"
onmouseout="this.style.backgroundImage='url(../images/LEC_Q1.jpg)';">

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

<button
onclick="document.getElementById('td_1').style.bac kgroundImage='url(../images/LEC_Q1_faded.jpg)';">
change td_1's image</button>

--
sm
Jul 24 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Thierry Schembri | last post by:
Hi ! I'm facing problems with a background image in a table (with IE & Opera), it works with FF : the <tr> has a background image, but the background repeats in each <td> ex : tr...
7
by: Keith Smith | last post by:
How can I change the background IMAGE (not just color) of a CELL in a table? I know that I can do this using CSS, but I really need to be able to do it using JavaScript. Anyone know how? Must...
3
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
3
by: Vam | last post by:
Hi, My program makes an HTML report which needs to be easily printable. On this report is a table, and one of the columns in the table needs to express a color. I've done this by setting the...
5
by: Derek Fountain | last post by:
I have a horizontal navigation bar, which is a single row table containing the right images. It "stretches" itself across the screen using a penultimate td like this: <td width="100%"...
5
by: proximus | last post by:
Hi, I am trying to change the background of table TD's. The problem is that I have no access to the HTML code. SO I am trying to alter this using Javascript/DOM in an external .js file. I...
5
by: Doug Laidlaw | last post by:
HTML validators say that "background" is not a valid attribute for a <td> tag I want to set an image as the background for one cell only, and to have the cell content on top of it. If I can't...
2
by: Mark | last post by:
IE creates an object of every ID'd HTML tag (so it appears), and each object sets a property for any parameter I set in the tag. For example, my HTML might be: <td id='cell1'...
4
by: Bob Altman | last post by:
Hi all, I posted an earlier question to the microsoft.public.inetserver.asp.general newsgroup asking how to set the background of a client-side table cell to a gradient, and I received this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.