Newbee Question

P

Paul Baker

Hi, I'm just learning this new scripting language.

I have created a little script (see below). The HTML builds a table and one
of the cells has a OnMouseOver parameter which I have set to my "Hello"
function. How do I reference the cell used to trigger "Hello". For
example, can I change the background color of the cells as the mouse passes
over them?

<TD onMouseOver="hello()">test</TD>

Within hello, how do I reference the TD cell that triggered hello?

I hope this makes sense.

Thanks in Advance!

Paul
Minneapolis






<html>
<head>
<title>CSS - Example 1</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- // Activate cloak
function hello()
/*****************************************************************
`description`
11/9/2003 12:37PM
*****************************************************************/
{

alert("test");
/* how do I reference the cell that invoked this script" */

} // hello()
// Deactivate cloak -->
</SCRIPT>
<link rel=stylesheet type="text/css"
href="css1.css"
title="Example 1">
</head>
<body>
<h1>Test H1</h1>
<table align="center" class=test>
<TR>
<TD onMouseOver="hello()">test</TD>
<TD>test</TD>
</TR>
<TR>
<TD>test</TD>
<TD>test</TD>
</TR>
</table>
<h1>Test H1</h1>
</body>
</html>
 
V

VK

<td onMouseOver="doWhatYouWantWith(this)"></td>

function doWhatYouWantWith(obj) {
obj.style.backgroundColor = myColor;
// and so on
}
 
M

Matt Eberts

Paul Baker said:
Hi, I'm just learning this new scripting language.

I have created a little script (see below). The HTML builds a table and one
of the cells has a OnMouseOver parameter which I have set to my "Hello"
function. How do I reference the cell used to trigger "Hello". For
example, can I change the background color of the cells as the mouse passes
over them?

Depending on the browser, event handlers either recieve an event object as a
parameter (Mozilla, DOM event model compliant browsers), or can access the
event object on the window object (IE).

Here's an example

function hello(event)
{

if(typeof event == "undefined")
{
event = window.event;
}

//event.target stores the object reference for the node that was the source
of the event for the DOM event model.
//event.srcElement stores the object reference for the node that was the
source of the event for IE
var src = event.target || event.srcElement;
}

Matt
 
E

Evertjan.

Paul Baker wrote on 09 nov 2003 in comp.lang.javascript:
<TD onMouseOver="hello()">test</TD>

Within hello, how do I reference the TD cell that triggered hello?

....
<TD id="myidea" onMouseOver="hello(this)">test</TD>
....

<script>
function hello(x){
alert(x.id)
alert(x.innerText) // IE
}
</script>
 
P

Paul Baker

Hi again,

Yes, I can see how "this" could be used. I can display parameters
associated with "this" but is it possible to actually change the parameters
dynamically. Like my example, can I change the background color of the cells
as the mouse passes over them?

Thank again!

Paul
 
E

Evertjan.

Paul Baker wrote on 10 nov 2003 in comp.lang.javascript:
Yes, I can see how "this" could be used. I can display parameters
associated with "this" but is it possible to actually change the
parameters dynamically. Like my example, can I change the background
color of the cells as the mouse passes over them?

Sure, why don't you try?

You will have to read up on css, perhaps

<TD onMouseOver="hello(this)">test</TD>
...

<script>
function hello(x){

x.style.backgroundColor = "yellow"
 
P

Paul Baker

Thanks...

Evertjan. said:
Paul Baker wrote on 10 nov 2003 in comp.lang.javascript:


Sure, why don't you try?

You will have to read up on css, perhaps



x.style.backgroundColor = "yellow"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top