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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Dec 2009
    Posts
    108
    Thanks
    22
    Thanked 2 Times in 2 Posts

    call event handler

    if it is done like this:
    Code:
    anElement.onclick=handleIt;
    
    function handleIt()
    {   this. ...     //'this' refer to the anElement
    }
    However, if you attach an event, quirk happens:
    Code:
    anElement.attachEvent("onclick",handleIt);
       // not sure if anElement.addEventListener("click",handleIt,false) works well
    function handleIt()
    {   this. ...     //'this' refer to an empty object ???????
    }
    why 'this' doesn't refer to the current target?
    anyone can help?

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Posts
    108
    Thanks
    22
    Thanked 2 Times in 2 Posts
    er anyone can help?

  • #3
    Regular Coder hdewantara's Avatar
    Join Date
    Aug 2009
    Location
    Jakarta, Indonesia.
    Posts
    366
    Thanks
    9
    Thanked 53 Times in 52 Posts
    element.attachEvent() for IE compatibility, right?
    "this" for event handlers in IE browser means window, not the element.

  • Users who have thanked hdewantara for this post:

    mehere8 (06-22-2010)

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Posts
    108
    Thanks
    22
    Thanked 2 Times in 2 Posts
    oh forgot that point ...

    thx


  •  

    Posting Permissions

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