Chapter 14.5.1. Retrieving Elements

Here’s a simple example: One of the most common things you’ll want to do is grab a specific element (sometimes called a node) from the document and do something to it. You’ll typically do this by setting an id attribute on the node and then calling document.getElementById(id_to_find). That wouldn’t be so bad, except for the fact that you use that all the time.

MochiKit replaces that common idiom with the much simpler getElement(id_to_find) or, if you want to really reduce typing, $(id_to_find). Even better, however, is that just about any function that takes a DOM node can take either a DOM node or a string with the ID of the node. In many cases, you won’t need to use getElement() or $()!

Then MochiKit ...

Get Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.