[Javascript] Problem w/Javascript, interpolation, functions, onclick
Paul Novitski
paul at juniperwebcraft.com
Wed Oct 25 12:18:55 CDT 2006
At 10/25/2006 08:24 AM, Nathan V. Patwardhan wrote:
>On Tue, Oct 24, 2006 at 11:52:36PM -0400, Matt Warden wrote:
>: Now, lord knows what you're trying to do with passing 'this'. If you
>: tell us what you want 'this' to refer to, we can probably help you out
>: there. Whatever you're wanting it to point to, it ain't.
>
>I'm modifying table cells based on an onclick event. So, for a table
>row that contains:
Nathan,
You don't need to pass 'this' explicitly as a parameter to a
behavioral event. See this example:
<tag id="something">something to click</tag>
...
var oSomething = document.getElementById("something");
if (!oSomething) return;
oSomething.onclick = jsDoSomething;
...
function jsDoSomething(evt)
{
// cancel event-bubbling
if (evt) { event = evt; }
event.cancelBubble = true;
// now act on the object whose behavior triggered
this function
var sClass = this.tagName; // etc.
}
I recommend that you peruse the excellent scripting examples at
Peter-Paul Koch's http://www.quirksmode.org/
Regards,
Paul
More information about the Javascript
mailing list