Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    wac
    wac is offline
    Regular Coder wac's Avatar
    Join Date
    Sep 2002
    Location
    Cary, North Carolina, USA
    Posts
    359
    Thanks
    2
    Thanked 0 Times in 0 Posts

    how to refer to the subject node in an event handler (this)

    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?
    Wayne Christian

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,032
    Thanks
    0
    Thanked 248 Times in 245 Posts
    works for me in IE5.5

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

    can you post the myFunc() function?

  • #3
    wac
    wac is offline
    Regular Coder wac's Avatar
    Join Date
    Sep 2002
    Location
    Cary, North Carolina, USA
    Posts
    359
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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
    </a>
    </td>
    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'.
    Wayne Christian

  • #4
    Regular Coder
    Join Date
    Sep 2002
    Location
    Surrey, UK
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try:

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

  • #5
    wac
    wac is offline
    Regular Coder wac's Avatar
    Join Date
    Sep 2002
    Location
    Cary, North Carolina, USA
    Posts
    359
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Is there anyway to stop the screen from flashing when one uses href="#" on an anchor????
    Wayne Christian

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Posts
    626
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try this:
    <a class='menuanchor' title='All Emails in All Segments'
    href="javascript:this.parentNode.onclick();return false">

  • #7
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    wac: Try adding ";return false;" at the end of the onclick attribute.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •