AJAX - The Complete Reference

(avery) #1

202 Part II: Applied Ajax^


YUI’s Connection Manager

Let’s start exploring YUI in the Ajax-focused plumbing provided by the library’s Connection
Manager package (http://developer.yahoo.com/yui/connection/). YUI is designed to be
modular, so you do not have to include every aspect of the library to employ features you
may be interested in. In the case of core Ajax support, you need to include only the base
YAHOO global object that includes a variety of utility functions and sets up an object wrapper
for the library and the connection library itself. The event library is also suggested but for
this simple example, it can be omitted. If you download the library locally and put it in a
directory named YUI in your site’s root, you can reference the required script files like so:

<script src="/yui/yahoo/yahoo.js"></script>
<script src="/yui/yahoo/event.js"></script>
<script src="/yui/connection/connection.js"></script>

Method Shorthand Description
AjaxTCR.util.DOM
.getElementById(id
[,startNode,deepSearch])

None Returns a single DOM element that matches
the id passed as a string, other wise a null value
is returned. A startNode can be passed to
indicate where the search begins from, other wise
the document is assumed. The Boolean
parameter deepSearch can be set to true to
per form a brute force search of DOM id attribute
values that may be useful when addressing
XML trees as commonly found in Ajax response
packets.
AjaxTCR.util.DOM
.getElementsById(id
[,startNode,deepSearch])

$id() Returns a single DOM element or list of DOM
elements that match the ID(s) passed as
strings. A startNode can be passed to indicate
where the search begins from, other wise the
document is assumed. The Boolean parameter
deepSearch can be set to true to per form
a brute force search of ID attribute values that
may be useful when addressing XML trees as
commonly found in Ajax response packets.
AjaxTCR.util.DOM
.getElementsByClassName
(className [,startNode])

$class() Returns a list of all the DOM elements with the
specified class name. More qualified searches,
such as for the stem of a class name, should
use the getElementsBySelector() method
instead.
AjaxTCR.util.DOM
.getElementsBySelector
(selector [,startNode])

$selector() Finds all the DOM elements matching the
selector string passed, starting from the
startNode or the document root if not
specified. The selector string should be a
string that is a well-formed CSS2 selector rule.

TABLE 5-5 AjaxTCR DOM Utility Methods
Free download pdf