Results 1 to 1 of 1

Thread: detachEvent using removeElement

  1. #1
    Join Date
    Dec 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default detachEvent using removeElement

    So i'm kind of making a dynamic menu based off of a user right clicking. Depending on where the click occurs i want different menu options to appear or even be disabled (no onmousedown event). I'm creating all of the menu options dynamically using createElement and attachEvent for the onmousedown event.

    since i'm using anonymous functions, i can't directly remove them usin detachEvent.

    Code:
    var menu = document.getElementById('menu');
    var item = document.createElement('DIV);
    item.innerHTML = 'menu item!';
    item.attachEvent('onmousedown', function() { alert('blah'); } );
    menu.appendChild(item);
    the following will not work...
    Code:
    item.detachEvent('onmousedown', function() { alert('blah'); });
    the question is... if i keep dynamically creating and removing elements from the menu, as opposed to trying to detach and retach events... would that be a better memory managment model? I guess I'm just worried about memory leaks without being able to detach any of these anonymous functions. Or are there any other suggestions as to how i might accomplish having different menu options when different elements are right clicked?

    a quick example of my code can be found at...
    http://pro.mork.carspot.com/~als/rtclick.html

    P.S. you'll have to goto view->source code since the right click is disabled
    Last edited by Ickyb0d; 12-14-2005 at 09:43 PM.

Bookmarks

Posting Permissions

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