Loading ...
Sorry, an error occurred while loading the content.

click listener on div not working in IE7 (works in FF)

Expand Messages
  • gpapayia
    Hi everyone, I m trying to add a listener on a div and then check to see which element is being clicked once the listener gets control. The following short
    Message 1 of 3 , Nov 1, 2007
    • 0 Attachment
      Hi everyone,

      I'm trying to add a listener on a div and then check to see which
      element is being clicked once the listener gets control. The
      following short javascript works in FireFox, but not in IE7. When I
      try to run it in IE7 I get a target.tagName is undefined error.

      Can anyone tell me why and what I can do to fix this?

      Thanks,
      George

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd">
      <html>
      <head>
      <title></title>
      <script type="text/javascript"
      src="http://yui.yahooapis.com/2.3.1/build/yahoo/yahoo-min.js" ></script>
      <script type="text/javascript"
      src="http://yui.yahooapis.com/2.3.1/build/event/event-min.js" ></script>
      <script
      src="http://yui.yahooapis.com/2.3.1/build/dom/dom-min.js"></script>
      <script type="text/javascript">
      YAHOO.util.Event.addListener(window, "load", function() {
      YAHOO.util.Event.addListener(YAHOO.util.Dom.get("maindiv"),
      "click", function(e) {
      alert(e.target.tagName);
      });
      });
      </script>
      </head>
      <body>
      <div id="maindiv" style="background-color: blue; width: 200px; height:
      200px;">
      <a href="#">testlink</a>
      </div>
      </body>
      </html>
    • Adam Moore
      ... George, instead of e.target, use YAHOO.util.Event.getTarget(e). -Adam
      Message 2 of 3 , Nov 1, 2007
      • 0 Attachment
        On Fri, Nov 02, 2007 at 01:32:54AM -0000, gpapayia wrote:
        > I'm trying to add a listener on a div and then check to see which
        > element is being clicked once the listener gets control. The
        > following short javascript works in FireFox, but not in IE7. When I
        > try to run it in IE7 I get a target.tagName is undefined error.

        George, instead of e.target, use YAHOO.util.Event.getTarget(e).

        -Adam
      • gpapayia
        thanks Adam..
        Message 3 of 3 , Nov 1, 2007
        • 0 Attachment
          thanks Adam..

          --- In ydn-javascript@yahoogroups.com, Adam Moore <adamoore@...> wrote:
          >
          > On Fri, Nov 02, 2007 at 01:32:54AM -0000, gpapayia wrote:
          > > I'm trying to add a listener on a div and then check to see which
          > > element is being clicked once the listener gets control. The
          > > following short javascript works in FireFox, but not in IE7. When I
          > > try to run it in IE7 I get a target.tagName is undefined error.
          >
          > George, instead of e.target, use YAHOO.util.Event.getTarget(e).
          >
          > -Adam
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.