Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Event trapping

46 views
Skip to first unread message

Dave "Crash" Dummy

unread,
Apr 30, 2012, 3:17:08 PM4/30/12
to
I have a table that contains 248 identical cells, differing only by the
enclosed text:

<td onMouseover="style.color='red'"
onMouseout="style.color='black'"
onClick="slashadd(this.innerText)">[string]</td>

The idea is to have the cell act like a hyperlink, with a "hover" color.
It works fine as shown, but is bulky. Is there some way I can use a single
script function to remotely capture and act on events in multiple cells?
--
Crash

Committed to the search for intraterrestrial intelligence.

Mayayana

unread,
Apr 30, 2012, 4:55:55 PM4/30/12
to
You can do something like this:

Sub DoHover()
window.event.srcElement.style.color = "#FF0000"
End Sub

Sub UnHover()
window.event.srcElement.style.color = "#000000"
End Sub

.....<TD onmouseover="DoHover()" onmouseout="UnHover()"......


You can also do something like this:

Sub document_onmouseover()
If window.event.srcElement.tagName = "TD" Then
window.event.srcElement.style.color = "#FF0000"
End If
End Sub

But personally I prefer to use classes and IDs:

Sub document_onmouseover()
If window.event.srcElement.className = "TD248" Then
window.event.srcElement.style.color = "#FF0000"
End If
End Sub

Sub document_onmouseout()
If window.event.srcElement.className = "TD248" Then
window.event.srcElement.style.color = "#000000"
End If
End Sub


.... with something like this:

<TABLE><TR><TD Class="TD248"></TD>
<TD Class="TD248"></TD>
<TD Class="TD248"></TD>
<TD Class="TD248"></TD>

--

"Dave "Crash" Dummy" <inv...@invalid.invalid> wrote in message
news:jnmofl$b7e$1...@dont-email.me...

Dave "Crash" Dummy

unread,
May 1, 2012, 7:01:52 AM5/1/12
to
Thank you! I knew there was a way, but I was fuzzy on the nomenclature.
I've added your letter to my "snippets" collection.

In this instance, I could have used Plan B because it applied to all TD
elements, but opted for Plan C for added versatility. I also added this:

Sub document_onclick()
If window.event.srcElement.className = "slash" Then
call slashadd(window.event.srcElement.innerText)
End If
End Sub

My table cells are reduced to <td class="slash">
--
Crash

English is not my native tongue; I'm an American.
0 new messages