469,600 Members | 2,219 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,600 developers. It's quick & easy.

Dynamically change bgColor of table cell?

kj

Is there a way to dynamically (e.g. upon onClick) change the bgColor
attribute of a table cell? I tried cell.setAttribute("bgColor",
someColor), where someColor was a string of the form "#RRGGBB",
but nothing happened.

Also, how can I set the mouse cursor to be an arrow when it hovers
over these table cells? (It's an insertion bar now.)

Thanks!

kj

Jul 20 '05 #1
5 3923
On Wed, 11 Feb 2004 22:46:35 +0000 (UTC), kj <kj***@lycos.com> wrote:
Is there a way to dynamically (e.g. upon onClick) change the bgColor
attribute of a table cell? I tried cell.setAttribute("bgColor",
someColor), where someColor was a string of the form "#RRGGBB",
but nothing happened.
Try

cell.style.backgroundColor = '#rrggbb';
Also, how can I set the mouse cursor to be an arrow when it hovers
over these table cells? (It's an insertion bar now.)


You can use CSS to do this.

<style type="text/css">
td {
cursor: default;
}
</style>

This will make the cursor display as the default shape (an arrow, usually)
over all table cells, assuming the cursor property is supported. If you
want to be more selective, change the selector to include a class.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2
"kj" <kj***@lycos.com> wrote in message
news:c0**********@reader2.panix.com...

Is there a way to dynamically (e.g. upon onClick) change the bgColor
attribute of a table cell? I tried cell.setAttribute("bgColor",
someColor), where someColor was a string of the form "#RRGGBB",
but nothing happened.

Also, how can I set the mouse cursor to be an arrow when it hovers
over these table cells? (It's an insertion bar now.)

Thanks!

kj

Will this help?

<html>
<head>
<title>cellfunc.htm</title>
<script type="text/javascript">
function doit(that,what) {
if (what != "") {
that.style.cursor = what;
} else {
that.style.background = "yellow";
}
}
</script>
</head>
<body>
<table border="1" width="200" height="200">
<tr valign="top">
<td id="cell1"
onmouseover="doit(this,'hand')"
onmouseout="doit(this,'auto')"
onclick="doit(this,'')">
<br> blah, blah, blah, blah, blah...
</td>
</tr>
</table>
</body>
</html>
Jul 20 '05 #3
"kj" <kj***@lycos.com> wrote in message
news:c0**********@reader2.panix.com...

Is there a way to dynamically (e.g. upon onClick) change the bgColor
attribute of a table cell? I tried cell.setAttribute("bgColor",
someColor), where someColor was a string of the form "#RRGGBB",
but nothing happened.

Also, how can I set the mouse cursor to be an arrow when it hovers
over these table cells? (It's an insertion bar now.)

Thanks!

kj

Cool!

One problem: I get #666 when I should get "black".
P.S. I modified one line to display the color on the status bar:

<div id="g1" onmouseout="window.status=''"
onmouseover="window.status=window.event.srcElement .strokeColor"
onclick="alert(window.event.srcElement.strokeColor )"></div>

This lets the user see the color without having to click.
Where did you learn about this vml stuff?
Jul 20 '05 #4
kj


Thanks. That worked great.

One tiny remaining problem is that even though the cursor is no
longer an text insertion cursor, it can select text. If the mouse
moves slightly when one clicks on a cell, some text gets selected.
Is there any way to prevent this from happening?

Thanks!

kj

Jul 20 '05 #5
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:NhMWb.13527$jk2.45500@attbi_s53...
Cool!

One problem: I get #666 when I should get "black".


[snip]

Sorry for the above message; it was for another thread...
Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Pete Kipe | last post: by
reply views Thread by Diane Yocom | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.