W3cubDocs

/Dojo

dojo/dom

Summary

This module defines the core dojo DOM API.

See the dojo/dom reference documentation for more information.

Methods

byId(id,doc)

Defined by dojo/dom

Returns DOM node with matching id attribute or falsy value (ex: null or undefined) if not found. If id is a DomNode, this function is a no-op.

Parameter Type Description
id String | DOMNode

A string to match an HTML id attribute or a reference to a DOM Node

doc Document
Optional

Document to work in. Defaults to the current value of dojo/_base/window.doc. Can be used to retrieve node references from other documents.

Returns: instance

Examples

Example 1

Look up a node by ID:

require(["dojo/dom"], function(dom){
    var n = dom.byId("foo");
});

Example 2

Check if a node exists, and use it.

require(["dojo/dom"], function(dom){
    var n = dom.byId("bar");
    if(n){ doStuff() ... }
});

Example 3

Allow string or DomNode references to be passed to a custom function:

require(["dojo/dom"], function(dom){
    var foo = function(nodeOrId){
        nodeOrId = dom.byId(nodeOrId);
        // ... more stuff
    }
});

isDescendant(node,ancestor)

Defined by dojo/dom

Returns true if node is a descendant of ancestor

Parameter Type Description
node DOMNode | String

string id or node reference to test

ancestor DOMNode | String

string id or node reference of potential parent to test against

Returns: boolean

Examples

Example 1

Test is node id="bar" is a descendant of node id="foo"

require(["dojo/dom"], function(dom){
    if(dom.isDescendant("bar", "foo")){ ... }
});

setSelectable(node,selectable)

Defined by dojo/dom

Parameter Type Description
node undefined
selectable undefined

© 2005–2017 JS Foundation
Licensed under the AFL 2.1 and BSD 3-Clause licenses.
http://dojotoolkit.org/api/1.10/dojo/dom.html