How can I get the name of the object calling a procedure through a DHTML event. So
that I can do the following:
CallingObject.style.left=XXX
At the moment I have a seperate procedure for each object.
TIA
-TiPaRa
:D ;) :p
Printable View
How can I get the name of the object calling a procedure through a DHTML event. So
that I can do the following:
CallingObject.style.left=XXX
At the moment I have a seperate procedure for each object.
TIA
-TiPaRa
:D ;) :p
Try:
event.srcElement.style.left=
Hmmm, It sort of works. How can I get the type of object it returns. I tried event.srcElement.type but it just returns [object].
I need it to return the name of a table when the top cell is clicked.
TIA again
-TiPeRa
:D ;) :p
You could do this (I'll show a possibility later), but I recommend you just alter the function definition to include an argument for the source of the event:
If your event is currently called like this:Code:function foo(esource) {
alert('Source Element = ' + esource);
}
Just alter the function calls to be:Code:Example 1:
<table>
<tr>
<td id='elt1' onclick="foo()">Something</td>
</tr>
<tr>
<td id='elt2' onclick="foo()">Something</td>
</tr>
</table>
The code above should work cross browser/platformCode:Example 2:
<table>
<tr>
<td id='elt1' onclick="foo('elt1')">Something</td>
</tr>
<tr>
<td id='elt2' onclick="foo('elt2')">Something</td>
</tr>
</table>
Or... (possibly IE version specific)
Assuming you have the code as in Example 1, alter your function to be:
Code:function foo() {
alert('Source Element ID = ' + event.srcElement.id);
}
Is this what you wanted?
Sorted, (maybe) just one more thing. How do I get the parent of the object:
<table id="tbltest">
<tr>
<td id='tdtest' onclick="foo()">Something</td>
</tr>
</table>
In this situation I need to get the tbltest object when tdtest is clicked. I could probably find it somewhere on MSDN but you're a lot more help ful.
-TiPeRa
:D ;) :p
Surprisingly enough:
This will give the id of the TR element which contains the TD. Here is the really surprising bit...Code:function foo() {
alert('Source Element ID = ' + event.srcElement.parentElement.id);
}
This code gives the parent of the parent of the parent, which is the TABLE containing the TBODY containing the TR containing the TDCode:function foo() {
alert('Source Element ID = ' + event.srcElement.parentElement.parentElement.parentElement.id);
}
Cool?? :D
Thanks a lot. It works great now.
-TiPeRa
:D ;) :p