Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-21-2012, 08:41 PM   PM User | #1
anotherJEK
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: 150
Thanks: 41
Thanked 1 Time in 1 Post
anotherJEK is an unknown quantity at this point
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
anotherJEK is offline   Reply With Quote
Old 09-21-2012, 09:48 PM   PM User | #2
anotherJEK
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: 150
Thanks: 41
Thanked 1 Time in 1 Post
anotherJEK is an unknown quantity at this point
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]);
                 }
              }
          }
anotherJEK is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:45 PM.


Advertisement
Log in to turn off these ads.