View Full Version : TD background changed onclick
freddybee
12-25-2002, 05:32 PM
Hi,
I would like to change the baground of a TD when the anchor inside is clicked.
...
<TD background="test.gif"><A HREF="http//www.sample.com" onclick="CallMe(this);">TEST</A></TD>
...
The CallMe function should know wich TD is the contener ...
but this.TD.background means nothing in javascript ...
any idea of the way to point towards the backgroud property of the TD in wich the link has been clicked ???
Thanks in advance
caldasgsm
12-25-2002, 06:30 PM
try
this.parentElement.background = ...
the parentElement should give you a handle for the element that contains the (this) element
freddybee
12-25-2002, 11:05 PM
Thank you ....
If I may why this.parentelement works when .....
getElementById(id).parentelement doesn't works when I have put an id for the anchor ???
;)
Have a play around with this
<table border="1" width="50%">
<tr id="tr1">
<td onclick="tr1.bgColor = '#FFFF00'">Click On</td><td> 0 </td><td onclick="tr1.bgColor = ''">Click Off</td>
</tr>
<tr>
<td id="tr2" onclick="tr2.bgColor = '#993366'">Click On</td><td onclick="tr2.bgColor = ''">Click Off</td><td> 0 </td>
</tr>
<tr id="tr3">
<td onmouseover="tr3.bgColor = '#0000FF'" onmouseout="tr3.bgColor = ''">M Over/Out</td><td> 0 </td><td> 0 </td>
</tr>
<tr>
<td id="tr4"> 0 </td><td> 0 </td><td onmouseover="tr4.bgColor = '#FFAAFF'" onmouseout="tr4.bgColor = ''">M Over/Out</td>
</tr>
</table>
ca_redwards
12-27-2002, 09:58 PM
In my HTML() bookmarklet library (http://www.angelfire.com/ca/redwards/html__.calendar.html), there is an example that pops up a websafe color palette to recolor the original page. Since IE and NS handle TD tags differently, I use a 1x1 transparent gif inside of a link inside of a TD. Everything gets an onclick event, and the link uses the javascript: protocol. That makes it work.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.