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

YAHOO.util.Dom.get

Expand Messages
  • ragtek_ragga
    Where s the difference between [CODE]YAHOO.util.Dom.get[/CODE] and [code]document.getElementById[/code]
    Message 1 of 5 , Oct 8, 2007
    • 0 Attachment
      Where's the difference between [CODE]YAHOO.util.Dom.get[/CODE] and
      [code]document.getElementById[/code]
    • foti-1@comcast.net
      YAHOO.util.Dom.get can take the following parameter: el Accepts a string to use as an ID for getting a DOM reference, an actual
      Message 2 of 5 , Oct 8, 2007
      • 0 Attachment
        YAHOO.util.Dom.get can take the following parameter:

        el <String | HTMLElement |Array> Accepts a string to use as an ID for getting a DOM reference, an actual DOM reference, or an Array of IDs and/or HTMLElements.

        So, for example, you can use it to get an array of items like so:

        var arr = YAHOO.util.Dom.get( ['id1', 'id2', 'id3'] );

        document.getElementById will take only a single string parameter and return only a single item.

        Peter


        -------------- Original message ----------------------
        From: "ragtek_ragga" <ragtek_ragga@...>
        > Where's the difference between [CODE]YAHOO.util.Dom.get[/CODE] and
        > [code]document.getElementById[/code]
        >
        >
      • Adam Moore
        ... Dom.get will accept a string id, an element reference, or an array of ids/elements. See the API docs:
        Message 3 of 5 , Oct 8, 2007
        • 0 Attachment
          On Mon, Oct 08, 2007 at 09:11:27PM -0000, ragtek_ragga wrote:
          > Where's the difference between [CODE]YAHOO.util.Dom.get[/CODE] and
          > [code]document.getElementById[/code]

          Dom.get will accept a string id, an element reference, or an
          array of ids/elements. See the API docs:

          http://developer.yahoo.com/yui/docs/YAHOO.util.Dom.html

          -Adam
        • Adam
          YAHOO.util.Dom.get() is like an extension to document.getElementById(). get() can work with arrays of IDs passed in as arguments and can return arrays of
          Message 4 of 5 , Oct 8, 2007
          • 0 Attachment
            YAHOO.util.Dom.get() is like an extension to document.getElementById().

            get() can work with arrays of IDs passed in as arguments and can
            return arrays of matched HTMLElements. With getElementById(), you'd
            need iteration for that type of functionality. It's pretty powerful -
            and saves a lot of code - when you can let YUI take care of that
            iteration for you (no need to mess around with instantiating an Array,
            push()-ing onto it, etc.). Much cleaner.

            Also, getElementById() accepts only one parameter: a String ID name.
            get() can accept a String or an HTMLElement. There may be points in
            your code when you'll need to call a certain function that acts upon
            an HTMLElement. Sometimes, you'll have a reference to that Element.
            Other times, you'll only have its String ID. get() would allow you to
            write a single function that can handle either case. (This sounds
            strange, but trust me, it can be necessary sometimes, especially if
            you're building a modular, clean API).

            In all, if you're using a String ID to return a reference to an
            HTMLElement, you won't notice much difference. If you need to obtain
            references to HTMLElements with some degree of flexibility or want to
            save yourself iterating through blocks of code, get() becomes a great
            choice.
          • ragtek_ragga
            thx 4 the fast answers
            Message 5 of 5 , Oct 8, 2007
            • 0 Attachment
              thx 4 the fast answers
            Your message has been successfully submitted and would be delivered to recipients shortly.