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

36643Re: Basic Event Utility example only half working?

Expand Messages
  • Josh Lizarraga
    Aug 25, 2008
    • 0 Attachment
      Thanks a ton!

      --- In ydn-javascript@yahoogroups.com, Satyam <satyam@...> wrote:
      >
      > The problem is that you are setting the event listener before the
      > element you are setting the listener on is ready. By the time your
      code
      > executes, the element is not yet there in the page,
      > document.getElementById will simply return null. However, if you call
      > Event.addListener using the name of the object, if the object is not
      > found, the Event utility will start a timer and check the object a
      > little later when there is a chance that the element might be there.
      >
      > You should not execute code relying on HTML element without making sure
      > those elements do exist. See:
      >
      > http://developer.yahoo.com/yui/event/#onavailable
      >
      >
      >
      > Satyam
      >
      >
      > Josh Lizarraga wrote:
      > > Check out the "Basic Events" section on this page:
      > >
      > > http://developer.yahoo.com/yui/event/
      > >
      > > This is the example:
      > >
      > > var oElement = document.getElementById("elementid");
      > > function fnCallback(e) { alert("click"); }
      > > YAHOO.util.Event.addListener(oElement, "click", fnCallback);
      > >
      > > On my page, I implemented it like this, which DID NOT WORK:
      > >
      > > var oElement = document.getElementById("mm3_DemoPage_HeaderLogo");
      > > function fnCallback(e) { alert("click"); }
      > > YAHOO.util.Event.addListener(oElement, "click", fnCallback);
      > >
      > > This example, however, DID WORK:
      > >
      > > var oElement = document.getElementById("mm3_DemoPage_HeaderLogo");
      > > function fnCallback(e) { alert("click"); }
      > > YAHOO.util.Event.addListener("mm3_DemoPage_HeaderLogo", "click",
      > > fnCallback);
      > >
      > > ...am I missing something?
      > >
      > >
      > > ------------------------------------
      > >
      > > Yahoo! Groups Links
      > >
      > >
      > >
      > >
      > > No virus found in this incoming message.
      > > Checked by AVG - http://www.avg.com
      > > Version: 8.0.138 / Virus Database: 270.6.7/1631 - Release Date:
      24/08/2008 12:15
      > >
      > >
      > >
      > >
      >
    • Show all 4 messages in this topic