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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Custom Event Attributes

    I'm working with custom events, and I've run into a problem - when I dispatch the event (with dispatchEvent()) to the body of the page, it won't fire the function I assigned to the event handler, and instead I have to use event listeners. Is there any way to overcome this problem?

    Any help is greatly appreciated. Thanks!

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    If in an HTML attribute:

    document.addEventListener("mycustomevent", function(event) {
    eval(event.target.getAttribute("onmycustomevent"));
    }, true);

    Else if assigned via javascript:

    document.addEventListener("mycustomevent", function(event) {
    event.target.onmycustomevent();
    }, true);

    You might want to change the true to the false if you want to fire it on bubbling instead of on capturing, but whatever. The gist is there.
    Last edited by jkd; 11-30-2003 at 04:48 PM.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, jkd!

    You might want to change the true to the false if you want to fire it on bubbling instead of on capturing, but whatever.
    I didn't even realize, heh. *changed*


  •  

    Posting Permissions

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