SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    event handling for a dynamically created element

    Dear All,

    Please can some one help me with this seemingly unresolvable chicken and egg situation.

    Pseudo Code
    ------------

    onmouseover of menu button create drop down menu

    add to DOM

    addEventListener for new down menu

    handle event when mouse over new drop down

    ---------------------------------------------------

    So I can create the drop down I can add the event listener
    but I cannot code the event handler.

    When ever I add the code

    newDropDown.onmouseover = function(){
    // handle the event here
    }

    I get error newDropDown not defined. I am assuming that this is because on the first time through the code the dynamically created element.

    Sure there must be some way to use the eventlistener that has been added once the new element has been created.

    Please can someone point me in the right direction.

    Regards

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to show some not-so-pseudo code.
    Tab-indentation is a crime against humanity.


Tags for this Thread

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
  •