473,385 Members | 1,814 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,385 software developers and data experts.

How to change cell color dinamically ?

60
I'd like to know if there's a way to make the color of a cell/button change using onMouseOver. Is there some sort of "built-in" function to do this ?



Thank you....

p.s: If possible, the color should be random.
Aug 16 '07 #1
2 1469
pbmods
5,821 Expert 4TB
Heya, pplers.

You must have meant to post this in the JavaScript forum. All taken care of, now.
Aug 16 '07 #2
xNephilimx
213 Expert 100+
Hi there.
There's no built in function to do that, as there's not only one way, but a series of methods for manipulating the styles of an element. Try something like this, this is the way that I like the most cause it's non intrusive script:

Expand|Select|Wrap|Line Numbers
  1. window.onmouseover = Over;
  2.  
  3. function Over(e) {
  4.     var obj = e.target || window.event.srcElement;
  5.     if(obj.tagName == "TD") {
  6.         obj.style.background = "#ffc";
  7.         obj.onmouseout = Out;
  8.     }
  9. }
  10.  
  11. function Out(e) {
  12.     var obj = e.target || window.event.srcElement;
  13.     if(obj.tagName == "TD") {
  14.         obj.style.background = "none";
  15.     }
  16. }
  17.  
This will make any td of any table "highlightable" when you hover the mouse on it.
If you want to make it only work on tables with a certain class name you'll then want to check the obj's class name, like this:


Expand|Select|Wrap|Line Numbers
  1. window.onmouseover = Over;
  2.  
  3. function Over(e) {
  4.     var obj = e.target || window.event.srcElement;
  5.     if(obj.tagName == "TD") {
  6.         if(obj.className == "theClass") {
  7.             obj.style.background = "#ffc";
  8.             obj.onmouseout = Out;
  9.         }
  10.     }
  11. }
  12.  
  13. function Out(e) {
  14.     var obj = e.target || window.event.srcElement;
  15.     if(obj.tagName == "TD") {
  16.         if(obj.className == "theClass") {
  17.             obj.style.background = "none";
  18.         }
  19.     }
  20. }
  21.  
Kind regards,
The_Nephilim

I'd like to know if there's a way to make the color of a cell/button change using onMouseOver. Is there some sort of "built-in" function to do this ?



Thank you....

p.s: If possible, the color should be random.
Aug 16 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Reply Via Newsgroup | last post by:
Folks, Say I have a table, ten columns, ten rows - Each with a word in it. I want to change the values of some/all of the cells in the table via a hyperlink. How do I reference each cell and...
1
by: Michael | last post by:
How can I use onclick to change a table cell background color. I know I can use this.className=? to change the classname. But then I would have to put the code into every single table cell. I...
3
by: michael | last post by:
I'm changing colors of table cells like this: <style type="text/css"> ..over {background-color: #bedddc} ..out {background-color: #99cccc} </style> <td onmouseover="this.className='over'"...
4
by: Dacian | last post by:
Hi, I´m trying to place a javascript navigation menu inside a cell of a table in my page, the problem is that the constructor of the menu object has parameters for menu positioning and size and...
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 | +---+---+
1
by: craigkenisston | last post by:
I have a project, in which in my default.aspx page, I dinamically load a user control in codebehind, in the pageload, that manages the website : Control objPageSkin = null; HtmlForm objForm =...
2
by: Fabio Cavassini | last post by:
I have this code that load HTML tags (no including <html> or <body>) into a DIV dinamically... after correctly retrieving the HTML, I assign it to my DIV Container ...
32
by: Mateo | last post by:
I have char *array and it is dinamically alocated.... When I pass it to other function, I need to determine size of this array.... Problem: sizeof operator does not work with dinamically alocated...
3
by: John Smith | last post by:
I'm looking into this peace of code: protected void DropDown_SelectedIndexChanged(object sender, EventArgs e) { DropDownList list = (DropDownList)sender; TableCell cell = list.Parent as...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.