Updated October 4th 2007
Updated October 19th 2007
elmsByAttribute method in IE where the compression resulted in a wrong reference, returning incorrect results. Download the new version and it will be fine.
DOMAssistant is plainly an extremely efficient way to work tightly on conjunction with the DOM without worrying about web browser caveats and inconsistencies. No matter what you do, you will always get back a proper reference to the actual DOM element, or an
Basically, what chainability means is that you can perform some method on an object and then immediately follow that result with a dot and a new method acting on what was returned. This leads to the nice possibility of writing short, concise and easy-to-understand code like this:
The code above finds all the elements with the CSS class “mandatory” amongst the children of an element named “container”. It then loops through all of the returned elements and applies an
onblur event to them to call a function named
As you can see from this, fairly complex operations will be one-liners in the code, helping you to focus on other tasks. There’s no limit to how much chaining you can do. However, my recommendation to get legible code enabling an easy overview, use chaining, but moderately. If you do it in ten consecutive steps it might look cool, but it’s not that much fun trying to maintain or debug it later.
There are two DOMAssistant methods that don’t support chaining; so-called end-of-the-line methods to me. You will find this natural, though, since these two methods are
getStyle, which respectively returns a boolean and a style value. All other methods can be chained.
AJAX is nowadays used in almost every project, in some way or another. This virtually led to the mandatory existence of an AJAX module for DOMAssistant, which is very basic. It supports a
get method where you send in an URL to get content from, and a function to call once that data is retrieved. Example usage:
The first parameter in the called function will be the
responseText from the AJAX call.
In the first version of DOMAssistant, support existed to execute any number of functions as soon as the DOM of a document has finished loading. There were some misunderstandings, though, that they had to be entered in the
DOMAssistantLoad file. Making it easier to understand, and at the same time clearly highlighting the benefit of such a method, I have introduced a
Behind the scenes, XPath is now used for the
elmsByAttribute methods, for web browsers that support that. The idea is that one should experience faster performance and in the future, when it’s more widely supported, XPath opens up for a lot of advanced DOM selections.
Changes from previous version
Two methods have changed name:
getElementsByClassName is now named
getElementsByAttribute is now
elmsByAttribute. The reasoning behind this is mostly that since native web browser support for
getElementsByClassName is starting to pop up, it shouldn’t be confused or mixed up with the method DOMAssistant offers. Another, smaller, reason is that people thought those method names were a bit long, so now they are at least slightly shorter.
Online documentation is available in the DOMAssistant web site. There you can also download a complete PDF documentation (PDF link) and a diagram over DOMAssistant’s modules and methods (PDF link).
Sign up for updates
If you want to stay on top of what’s happening with DOMAssistant, updates etc, send me an e-mail at domassistant [at] robertnyman [dot] com to verify your your e-mail address, and I will e-mail you when anything important happens.
When developing version 2.0, I had a great support from a number of people when it came to testing, suggestions or basically just being there for me. These are (and if I miss anyone now, just let me know!):
Go use it!