View Full Version : how to refer to the subject node in an event handler (this)

10-23-2003, 05:18 AM
I thought that I could refer to the current node using the 'this' keyword, as in

<button onclick='myFunc(this)'> blah </button>

where the button object would be passed into myFunc(), however, when I trace the call, I get a null object. What am I doing wrong?

10-23-2003, 06:15 AM
works for me in IE5.5

<button name="btn" onclick='alert(this.name)'> blah</button>

can you post the myFunc() function?

10-23-2003, 03:17 PM
Ok. Here's a fragment of exactly what I'm doing

<td class='menuitem' onclick="emailDeleteDlg('main','emails','rmallemail','')">

<a class='menuanchor' title='All Emails in All Segments'
href='javascript:this.parentNode.onclick();void 0'>
All Emails in All Segments
I get a popup indicating that this.parentNode is null

The TD is code generated by a tag library so I can't mess with that. The anchor is part of the (body/content, not sure of the right term) of one of the tags. I'm using the anchor because it has accessibility capabilities, so I can add 'accesskey' and 'title'.

10-23-2003, 04:51 PM

<a class='menuanchor' title='All Emails in All Segments'
href="#" onclick="this.parentNode.onclick();return false">

10-23-2003, 06:56 PM
Is there anyway to stop the screen from flashing when one uses href="#" on an anchor????

10-23-2003, 07:37 PM
try this:
<a class='menuanchor' title='All Emails in All Segments'
href="javascript:this.parentNode.onclick();return false">

10-23-2003, 07:48 PM
wac: Try adding ";return false;" at the end of the onclick attribute.