5 Replies Latest reply on Dec 4, 2008 11:56 PM by kiwi_ziesch

    problem with addEventListener

    elfguy
      I'm trying to call a javascript function on a mouseover event on a series of thumbnails, but it's not working. No error is printed, nothing happens when I mouse over. The alert doesn't show. I tried everything I could think of, what is wrong with it?

      document.getElementById("tarea").innerHTML += "<a target=_blank href='" + lurl + "'><img border=0 id='thumb_img" + i + "' src='" + lthumb + "'></a>";
      document.getElementById("thumb_img"+i).addEventListener("mouseover", function() { alert("hello?"); });
        • 1. Re: problem with addEventListener
          laurent22300
          Hi, just guessing, but shouldn't it be "mouseOver" and not "mouseover"?
          • 2. Re: problem with addEventListener
            kiwi_ziesch Level 1
            I´ve got a similar problem with adding EventListeners.
            I´ve made small changes to my app - move some code...nothing essential and now all eventlisteners don´t react.
            I´m adding like this:

            var div = document.createElement( 'div' );
            div.className = 'folder';
            div.id = ref_id + f_id;
            div.style.marginTop = '2px';
            div.addEventListener( 'mouseover', doOverFolder );
            div.addEventListener( 'mouseout', doOutFolder );
            div.addEventListener( 'click', doDelete );

            It has nothing to do with the notation of "mouseOver" or "mouseover".
            It already worked :(

            Maybe some of you had similar probs?
            • 3. Re: problem with addEventListener
              kstephens2 Level 1
              elfguy:

              Instead of doing it as HTML like that you could do something like this ( debug this ):

              var a = document.createElement('a')
              a.href = lurl

              var img = document.createElement('img')
              img.src = lthumb
              img.id = 'thumb_img' + i
              img.addEventListener('mouseover',function(){ air.trace('hello') }

              a.appendChild(img)
              document.getElementById('tarea').appendChild(a)

              In regards to kiwi_ziesch:

              Can do add the following and see if it traces:

              div = document.createElement('div')
              div.addEventListener( 'mouseover', function() { air.trace('mouseover') }, false)

              That should tell you if the problem is in the mouseover or in the function you are calling
              • 4. Re: problem with addEventListener
                kiwi_ziesch Level 1
                I added the mouseover-Listener with your suggested function and it tells nothing.
                I just don´t know what´s wrong.
                I´m adding some div´s to a "main"-div container. some have eventlistener´s and some not. all have a seperate ID and so on. For some created div´s I add content via innerHTML = '<div class="...">text</div>'. But I don´t add Listeners in this way. May this causes the error?
                • 5. Re: problem with addEventListener
                  kiwi_ziesch Level 1
                  and it really was the mistake.
                  now I add all elements only via document.createElement.