Releasing DOMAssistant 2.0 - Chainability, AJAX module, DOMReady, XPath and more
Updated October 4th 2007
The DOMAssistantCompressed JavaScript file has been updated. My compression approach was a little too effective for the special DOMReady fix for Internet Explorer, so necessary code for optimal performance was unfortunately removed. This has now been addressed, so please download the new version if you use the compressed file.
Updated October 19th 2007
The DOMAssistantCompressed JavaScript file is updated again. I noticed a problem with the elmsByAttribute method in IE where the compression resulted in a wrong reference, returning incorrect results. Download the new version and it will be fine.
Tired but proud, I would like to announce the 2.0 release of DOMAssistant! Refactored code and new features will improve what is already a vital and must-have JavaScript library for me.
Why DOMAssistant?
Some of you might say that there are already an abundance of JavaScript libraries out there, so why keep on working on yet another one? The reasons for me are simple. The existing ones are generally bloated and contain way more functionality than often needed, most aren’t modular and, most important of all, if you use some part of it, you’re locked into their syntax for whatever else you want to do.
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 array of references to DOM elements. This means that you can use DOMAssistant for the tasks you want to, and then just hook in your own scripts or other JavaScript libraries wherever and whenever you want to.
New features
I talked to people, compared to other JavaScript libraries and thought about what I could do to improve my and everyone else’s usage of DOMAssistant, and came up with some nice new features.
Chainability
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:
$("container").elmsByClass("mandatory").addEvent("blur", validateInput);
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 validateInput.
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.
Exceptions
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 hasClass and getStyle, which respectively returns a boolean and a style value. All other methods can be chained.
AJAX module
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:
DOMAssistant.AJAX.get("URL", callbackFunction)
The first parameter in the called function will be the responseText from the AJAX call.
Easier DOMReady
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 DOMReady function. It can be used in any JavaScript file you want to, and it is called like this:
DOMAssistant.DOMReady(nameOfFunction);
XPath support
Behind the scenes, XPath is now used for the elmsByClass and 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 elmsByClass and 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.
Documentation
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.
Acknowledgements
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!):
- Martin Jansson - excellent testing, thanks!
- Niklas Lindström
- Roger Johansson
- Emil
- Henrik Box
Go use it!
DOMAssistant can co-exist with other JavaScript libraries, so download it, play around with it and fall in love! ![]()



