Question:
Simple javascript question, please help.?
GeNiToR
2006-12-07 14:27:05 UTC
Hi there, I have a table and a cell with a background. I want the background of the table to change to a desired picture on mouseover using javascript.


- Home
Blah





And here is my javascript.




Thanks for help guys. For some reason YAHOO ANSWERS won't let me post the whole thing with GETELEMENT BY ID. I hope you understand what's on there.
Three answers:
nljth123
2006-12-07 14:55:33 UTC
I see what you're doing... the best way to handle something like this is to change the className of the table row you want to effect. To do this, use the className property of the cell object. There are three parts to this: 1) css 2) javascript and 3) html



The CSS:

Add the following style declarations to the top of your page (within the section):







The Javascript:

In your table cell, add the following code:











My table cell




That should do it. In summary, change the className of the table row. Do a search on Google for this technique if my post isn't elaborate enough.
jake cigarâ„¢ is retired
2006-12-07 15:38:00 UTC
this is the answer!!! no, not that.. "this". "this" is a magic var inside html for javascript calls... you say onclick="change(this)"



and then inside change you have a parameter that is the elementID of the element in question!



No IDs, no getelements... just sweet tiny code... next step is to dynamically assign onclick to every tab cell... that's a couple of loops!!!



Oh, and 's go inside 's!!



and don't slap a style.background... on the cells, just change their class!
djlazi
2006-12-07 15:04:05 UTC




those should read

document.

getElementById('mytable').

style.

backgroundImage = "url(img57345mo.jpg)";

please take out the line breaks it should be all one line



or whatever image you want to put here.

That can be anywhere on the page, but you can put it in your head. Change the images to whatever you want. Make sure your table has an id tag set.



















HERe



You of course can use onclick etc etc...

I believe this is one way to do it.



I hope this helps,

Good Luck


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...