SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    xAddEventListener help

    I am trying to use the X Library to add an event listener to an element. It works just fine in IE 6, but not in firefox. Basically, I want to add an onclick event so when the div is clicked, it goes to the link I specify. Here is my code.

    Code:
    addNewNode(parent.id);
    xAddEventListener(parent.firstChild,"click", addLink, false);
    
    function addNewNode(parentID){
        var parent = document.getElementById(parentID);
        var newNode = new xCreateElement("div");
        parent.insertBefore(newNode,parent.childNodes[0]);
        parent.style.top = "-40px";
    }
    
    function addLink(e){
        alert("hello");
    }
    When I click on the element in IE, it alerts "Hello". When I click on it in Firefox, nothing happens. I know that xAddEventListener works in Firefox because the demos on www.cross-browser.com work just fine in Firefox.

    Any ideas?

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi vipergtsrz,

    Welcome to SPF!

    Without seeing the rest of your code I can't be sure - but it is possible that parent.firstChild is a #text node in FF. If that is the case, just use something like xFirstChild.

    Thanks!

  3. #3
    SitePoint Member
    Join Date
    Nov 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I thought it had something to do with not using the x library somewhere so I used xGetElementById and xParent and xFirstChild to get it to work. Thanks for the tip and the warm welcome


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
  •