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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Location
    Now Southern Oregon. I was born and had lived my life in Los Angeles until relocating last year (2010)
    Posts
    215
    Thanks
    52
    Thanked 1 Time in 1 Post

    applying click event to nested element in IE??

    I have a situation where a series of divs are created in a grid. Each has an event handler that is registered on the div id click event.
    Each div has a span element and inside the span element is a text character.
    The.
    In DOM compliant browsers the user can click on the charater itself and the
    click event will be handled correctly.
    In Internet Explorer (testing in v7) the user has to click on the part of the div
    that is visible around the characters field, but not on the character itself.
    I tried setCapture() but it still doesn't handle the click event then the user
    clicks on the character itself.
    Code:
    /* script generated content with dom createELement() etc...
    
    <div id="(assigned id)" (click event assigned handler)> <span class="styleRules"> (char) </span> </div>
    */
    // gameSet is an array containing the list of ids assigned the div elements
    // this is run AFTER all the content is appended
              if(document.attachEvent)
                {
                 for(var i = 0; i < gameSet.length; i++)
                    {
                     var el = document.getElementById(gameSet[i]);
                         //// el.setCapture();
                         el.attachEvent('onclick', function(){ IEFindId() });
                    }
                 }
    If the user clicks on the <span>char</span> element nothing happens
    What is supposed to happen:
    The coordinates of the div handling the click, swap with another divs coordinates
    Thanks for time and attention
    JK

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Location
    Now Southern Oregon. I was born and had lived my life in Los Angeles until relocating last year (2010)
    Posts
    215
    Thanks
    52
    Thanked 1 Time in 1 Post

    I got it

    Code:
       // previous code ....
             if(document.attachEvent)
                {
                 for(var i = 0; i < gameSet.length; i++)
                    {
                     var el = document.getElementById(gameSet[i]);
                         //// el.setCapture();
                         el.attachEvent('onclick', function(){ IEFindId() });
                         el.childNodes[0].attachEvent('onclick', function(){ IEFindId() })
                    }
                 }
          // etc
    // then code in IEFindId()
    function IEFindId()
              {
               for(var i = 0; i < idLst.length; i++)
                  {
                   if(window.event.srcElement.id == idLst[i][4] || window.event.srcElement.parentNode.id == idLst[i][4])
                     {
                      swap(idLst[i][4]);
                     }
                  }
              }


  •  

    Posting Permissions

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