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
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    element.addEventListener in nested div problem

    Code:
    function offPar(){
       alert(this.offsetParent.id);
    }
    
    function init(){
    var mine = document.getElementById("mid");
    var other = document.getElementById("inner");
    
    mine.addEventListener("click", offPar, false);
    other.addEventlistener("click", offPar, false);
    
    }
    
    window.addEventListener('load', init, false);
    
    HTML :
    <div id = "content"> 
    
     <div id = "mid"> 
        <div id = "inner">
           <p class = "par">
           </p>
        </div>
     </div>
    
    </div>
    I can add an event listener to the #mid div but I can't to the #inner div.
    Anyone now why this is? Sorry I can't provide more info. That's all I Know!

    TTFN
    John

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,974
    Thanks
    15
    Thanked 229 Times in 229 Posts
    It's because javascript is case sensitive and this: other.addEventlistener should be this: other.addEventListener.

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    bows head in shame. opps! Thanks for proof-reading that for me... uh ... I'll just leave now.

    TTFN
    John


  •  

    Posting Permissions

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