Closed Thread Icon

Preserved Topic: how to report color of table cell? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=18452" title="Pages that link to Preserved Topic: how to report color of table cell? (Page 1 of 1)" rel="nofollow" >Preserved Topic: how to report color of table cell? <span class="small">(Page 1 of 1)</span>\

 
alphakid42
Obsessive-Compulsive (I) Inmate

From:
Insane since: Dec 2002

posted posted 12-29-2002 03:27

i have a table with cell backgrounds set to various colors through frontpage
and want to report the HEX color value for the clicked cell via 'alert'
without hard-coding the result for each cell as in: <td onClick="alert('Color is #FF66CC')">
and if possible, without naming each cell as in: <td name="cell_1">

i'm thinking that <table onClick="showColor();" could launch a javascript function to:
a) obtain "theElement" - an object reference for the clicked cell
b) interrogate theElement for background color hex value
c) report that value with javascript alert(theElement.bgcolor);

any thoughts on how to write such a function?
i would appreciate any help on this.

thanks!
alphakid42
also, anyone know what 'Disable Slimies in This Post' means? (he asked with fear).

alphakid42

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 12-29-2002 03:40

The easiest way to obtain theElement is through the "this" keyword in the onclick function. You can pass it into the showColor function, like so:

<td onclick="showColor(this);">

Then, the showColor function can use that argument:

function showColor(theElement)
{
alert('Color is ' + theElement.style.backgroundColor);
}

alphakid42
Obsessive-Compulsive (I) Inmate

From:
Insane since: Dec 2002

posted posted 12-29-2002 04:04

hi, mad scientist.
thanks for your splendid reply re: js 'this' -- about like 'self' for the current window.

best holiday gift i got!

scott
new asylum inmate.
alameda, california (it's raining cats and dogs here).

alphakid42

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 12-29-2002 07:21

You're welcome =)

The "this" keyword can be used in *any* event of an element. (onclick, onmouseover, onkeydown, you name it.) Actually, it can be used for any *method* of an *object*... but I don't know if you know what those are yet. (events are a type of method, and html elements are one of many types of objects.)

« BackwardsOnwards »

Show Forum Drop Down Menu