- 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.
-------------- Original message ----------------------
From: "ragtek_ragga" <ragtek_ragga@...>
> Where's the difference between [CODE]YAHOO.util.Dom.get[/CODE] and
- On Mon, Oct 08, 2007 at 09:11:27PM -0000, ragtek_ragga wrote:
> Where's the difference between [CODE]YAHOO.util.Dom.get[/CODE] andDom.get will accept a string id, an element reference, or an
array of ids/elements. See the API docs:
- 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