Diviner

Class JX.DOM

Definedsrc/lib/DOM.js:311
GroupDOM and Markup
ExtendsJX.Base

Query and update the DOM. Everything here is static, this is essentially a collection of common utility functions.

Tasks

Attaching Event Listeners

Changing DOM Content

Updating Nodes

Serializing Forms

Testing DOM Properties

Convenience Methods

Finding Nodes in the DOM

Changing View State

Unspecified

Methods

private static _getAutoID(node)

parameterswildnode
returnwild
This method is not documented.

private static void _insertContent(parent, content, mechanism, reverse)

parametersNodeparentNode to add content to.
mixedcontentContent to add.
functionmechanismCallback for actually adding the nodes.
boolreverseTrue if array elements should be passed to the mechanism in reverse order, i.e. the mechanism prepends nodes.
returnvoid

Internal, add content to a node using some specified mechanism.

private static _mechanismAppend(node, content)

parametersNodenodeNode to append content to.
NodecontentNode to append.
returnwild

Internal, add content to a node by appending.

private static void _mechanismPrepend(node, content)

parametersNodenodeNode to prepend content to.
NodecontentNode to prepend.
returnvoid

Internal, add content to a node by prepending.

static alterClass(node, className, add)

parameterswildnode
wildclassName
wildadd
returnwild
This method is not documented.

static void appendContent(node, content)

parametersNodenodeNode to append the content of.
mixedcontentContent to append.
returnvoid

Append content to some node. This method uses the same content semantics as other Javelin methods, see JX.$N() for an explanation. You can also setContent() or prependContent().

static Dict convertFormToDictionary(form)

parametersNodeformThe form element to convert into a dictionary.
returnDictA dictionary of form values.

Converts a form into a dictionary mapping input names to values. This will overwrite duplicate inputs in an undefined way.

static List convertFormToListOfPairs(form)

parametersNodeformThe form element to convert into a list of pairs.
returnListA list of <name, value> pairs.

Converts a form into a list of <name, value> pairs.

Note: This function explicity does not match for submit inputs as there could be multiple in a form. It's the caller's obligation to add the submit input value if desired.

static Node find(root, tagname, sigil)

parametersNoderootRoot node to search beneath.
stringtagnameTag name, like 'a' or 'textarea'.
stringsigilOptionally, sigil which selected node must have.
returnNodeNode uniquely identified by the criteria.

Select a node uniquely identified by a root, tagname and sigil. This is similar to JX.DOM.scry() but expects exactly one result.

static void focus(node)

parametersNodenodeNode to move cursor focus to, if possible.
returnvoid

Focus a node safely. This is just a convenience wrapper that allows you to avoid IE's habit of throwing when nearly any focus operation is invoked.

static void hide()

parameters...One or more nodes to set "display: none" on.
returnvoid

Hide one or more elements, by setting display: none; on them. This is a convenience method. See also show().

static htmlize(str)

parameterswildstr
returnwild
This method is not documented.

static JX.Event invoke(node, type, data)

parametersNodenodeThe node to invoke an event on.
stringtypeCustom event type.
dictdataEvent data.
returnJX.EventThe event object which was dispatched to listeners. The main use of this is to test whether any listeners prevented the event.

Invoke a custom event on a node. This method is a companion to JX.DOM.listen() and parallels JX.Stratcom.invoke() in the same way that method parallels JX.Stratcom.listen().

This method can not be used to invoke native events (like 'click').

static bool isNode(node)

parameterswildnodeSomething which might be a Node.
returnboolTrue if the parameter is a DOM node.

Test if an object is a valid Node.

static bool isType(node, of_type)

parameterswildnodeSomething which might be a Node.
string|listof_typeOne or more tags which you want to test for.
returnboolTrue if the object is a node, and it's a node of one of the provided types.

Test if an object is a node of some specific (or one of several) types. For example, this tests if the node is an <input />, <select />, or <textarea />.

JX.DOM.isType(node, ['input', 'select', 'textarea']);

static object listen(node, type, path, callback)

parametersNodenodeThe node to listen for events underneath.
string|listtypeOne or more event types to listen for.
list?pathA path to listen on, or a list of paths.
functioncallbackCallback to invoke when a matching event occurs.
returnobjectA reference to the installed listener. You can later remove the listener by calling this object's remove() method.

Listen for events occuring beneath a specific node in the DOM. This is similar to @{JX.Stratcom.listen()}, but allows you to specify some node which serves as a scope instead of the default scope (the whole document) which you get if you install using @{JX.Stratcom.listen()} directly. For example, to listen for clicks on nodes with the sigil 'menu-item' below the root menu node:

var the_menu = getReferenceToTheMenuNodeSomehow();
JX.DOM.listen(the_menu, 'click', 'menu-item', function(e) { ... });

static void prependContent(node, content)

parametersNodenodeNode to prepend content to.
mixedcontentContent to prepend.
returnvoid

Prepend content to some node. This method uses the same content semantics as other Javelin methods, see JX.$N() for an explanation. You can also setContent() or appendContent().

static Node remove(node)

parametersNodenodeNode to remove.
returnNodeThe node.

Remove a node from its parent, so it is no longer a child of any other node.

static Node replace(node, replacement)

parametersNodenodeNode to replace.
mixedreplacementContent to replace it with.
returnNodethe original node.

Replace a node with some other piece of content. This method obeys Javelin content semantics, see JX.$N() for an explanation. You can also setContent(), prependContent(), or appendContent().

static void scrollTo(node)

parametersNodenodeNode to move document scroll position to, if possible.
returnvoid

Scroll to the position of an element in the document.

static list scry(root, tagname, sigil)

parametersNoderootRoot node to search beneath.
stringtagnameTag name, like 'a' or 'textarea'.
stringsigilOptionally, a sigil which nodes are required to have.
returnlistList of matching nodes, which may be empty.

Search the document for DOM nodes by providing a root node to look beneath, a tag name, and (optionally) a sigil. Nodes which match all specified conditions are returned.

static void setContent(node, content)

parametersNodenodeNode to set content of.
mixedcontentContent to set.
returnvoid

Set the content of some node. This uses the same content semantics as other Javelin content methods, see JX.$N() for a detailed explanation. Previous content will be replaced: you can also prependContent() or appendContent().

static void show()

parameters...One or more nodes to remove "display" styles from.
returnvoid

Show one or more elements, by removing their "display" style. This assumes you have hidden them with hide(), or explicitly set the style to display: none;.

static textMetrics(node, pseudoclass, x)

parameterswildnode
wildpseudoclass
wildx
returnwild
This method is not documented.

static uniqID(node)

parameterswildnode
returnwild
This method is not documented.