Additional comments powered by BackType
subscribe to my blog. You'll save me some bandwidth that way.
Additional comments powered by BackType
Tired of not knowing where you stack up against your friends on your favorite game, activity, or bodily function? We can help you with that.

Write More Efficient Javascript in YUI with CSS Selectors
This is an updated version of a previous article entitled Using DOM Query Libraries in YUI for the new version of YAHOO.util.Dom included with YUI 2.3.0 as well as including support for passing context nodes into Dom functions.
Here we are again. I just love those CSS Selectors. If you haven’t read Part One of the series linked above, I would encourage it to get a little background on why we’re attempting this approach.
Download the appropriate files:
Get the easy ALL-IN-ONE file: Y2.js (31 KB original source) OR Y2-p.js (11 KB minimized)
Get the files separately (if you want to use a custom selector library, or have already included DomQuery or jQuery): Y2-solo.js (9 KB original source) OR Y2-solo-p.js (4 KB minimized)
Also, first you’ll need to get Jack’s nice DomQuery class.
Download: Jack Slocum’s DomQuery Standalone File (24 KB) 1.0 Alpha 3 – Rev 4
Download: Jack Slocum’s DomQuery Standalone File Packed (7 KB) 1.0 Alpha 3 – Rev 4
You can use the jDomQuery standalone, or any jQuery version, (instead of DomQuery) linked in the previous article, but there is an unresolved bug with the getRegion method since jQuery doesn’t return actual Array’s. But if you’re not using that method, have at it.
What can I do with it?
I have not included ALL functions in this class, only the ones that take nodes in as arguments. If you use these functions, you are encouraged to use the unmodified versions contained in YAHOO.util.Dom. Functions not included here: getClientHeight, getClientWidth, getDocumentHeight, getDocumentScrollLeft, getDocumentScrollTop, getDocumentWidth, getViewportHeight, getViewportWidth.
Let’s see some documentation on this mother (if you’re wondering what the original functions do, see the original documentation).
addClass
Adds a CSS class to first matching node.
addClassAll
Adds a CSS class to all matching nodes.
hasClass
Tests the first result node returned to see if it has a CSS class.
hasClassAll
Tests all matching nodes to see if they have a CSS class.
removeClass
Removes a CSS class from first matched node.
removeClassAll
Removes a CSS class from all matched nodes.
replaceClass
Replaces a CSS class on first matched node with a new CSS class, or adds it if the old CSS class doesn’t exist.
replaceClassAll
Replaces a CSS class on all matched nodes with a new CSS class, or adds it if the old CSS class doesn’t exist.
get
Get first matched node.
getAll
Get all matched nodes.
batch
Executes a function against first matched node.
batchAll
Executes a function against all matched nodes.
generateId
Generates and assigns a unique ID attribute if not present on first matched element.
generateIdAll
Generates and assigns a unique ID attribute if not present on matched elements.
getChildren
Gets all HTMLElement children of the first matched node (does not include text nodes or whitespace)
getChildrenBy
Returns all HTMLElement children of the first matched node that pass a Boolean function test. (does not include text nodes or whitespace)
getAncestorBy
Returns the first HTMLElement ancestor of the first matched node that passes a Boolean function test. (does not include text nodes or whitespace)
getAncestorByClassName
Returns the first HTMLElement ancestor of the first matched node that has a CSS Class. (does not include text nodes or whitespace)
getAncestorByClassName
Returns the first HTMLElement ancestor of the first matched node that is a certain tag (does not include text nodes or whitespace)
getFirstChild
Returns the first HTMLElement child of the first matched node (does not include text nodes or whitespace)
getFirstChildBy
Returns the first HTMLElement child that passes a boolean function test from the first matched node (does not include text nodes or whitespace)
getLastChild
Returns the last HTMLElement child of the first matched node (does not include text nodes or whitespace)
getLastChildBy
Returns the last HTMLElement child that passes a boolean function test from the first matched node (does not include text nodes or whitespace)
getNextSibling
Returns the next HTMLElement sibling of the first matched node (does not include text nodes or whitespace)
getNextSiblingBy
Returns the next HTMLElement sibling that passes a boolean function test from the first matched node (does not include text nodes or whitespace)
getPreviousSibling
Returns the previous HTMLElement sibling of the first matched node (does not include text nodes or whitespace)
getPreviousSiblingBy
Returns the previous HTMLElement sibling that passes a boolean function test from the first matched node (does not include text nodes or whitespace)
getRegion
Gets the Region containing the first matched element.
getRegionAll
Gets all Regions containing all matched elements.
setStyle
Sets the style for the first matched node
setStyleAll
Sets style for all matched nodes
getStyle
Gets a specific style property from the first matched node
getStyleAll
Gets a specific style property from all matched nodes
setX, setY, setXY
Sets the horizontal placement (X), vertical placement (Y), or both (XY) of the first matched element
setXAll, setYAll, setXYAll
Sets the horizontal placement (X), vertical placement (Y), or both (XY) of all matched elements
getX, getY, getXY
Gets the horizontal placement (X), vertical placement (Y), or both (XY) of the first matched element
getXAll, getYAll, getXYAll
Gets the horizontal placement (X), vertical placement (Y), or both (XY) of all matched elements
inDocument
Find out whether the first matched element is in the current document
insertAfter
Take the first matched node of the first selector and insert after the first matched node of the second selector
insertBefore
Take the first matched node of the first selector and insert before the first matched node of the second selector
isAncestor
Find out whether the first matched node of the first selector is an ancestor of the first matched node of the second selector.
(Documentation is a bitch!)
Additional Information