DOM Utilities
Recall that Dojo intentionally does not attempt to replace core
JavaScript functionality; on the contrary, it only augments it where
value can be added so that you can write portable code and incur less
boilerplate. For this reason, you won't see direct replacements for
common DOM operations such as appendChild, removeChild, and so on. Still, there are
many utilities that could make DOM manipulation a lot simpler, and
this section is all about how Base helps to make that happen.
Ancestry
Base packs several useful functions that augment and
supplement common DOM functions. The first of these functions,
isDescendant, shown in Table 2-1, is
self-descriptive. You provide it two arguments (id values or actual nodes), where the
first argument is the node of interest and the second argument is a
potential ancestor. If the node of interest is in fact a member of
the potential ancestor's DOM tree, the function returns true.
Table 2-1. Base function for manipulating and handling the DOM
Name | Return type | Comment |
|---|---|---|
| Boolean | Returns a Boolean value indicating if a node has a particular ancestor or not and works in nested hierarchies as would be expected. |
Selectability
The need to make a text on the page unselectable via the cursor is not uncommon and sometimes can actually enhance usability. Virtually every browser has a specific way of accomplishing this task, but no need to worry—you have Dojo. Whenever the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access