DOMAssistant Core Module

The DOMAssistant Core module is required and it lays the groundwork for all DOMAssistant functionality. It consists of core functionality and a few important methods to work with.

$(cssSelector/elementReference)

The $ method is used to get a reference to one or several elements. It supports a CSS selector as a string, an already established element reference. It will return the matching element(s) with all the extra DOMAssistant methods applied. A call of any of those methods will fail silently, if the $ method returned an empty array.

Parameters

Send in a CSS selector or an object reference.

Return value

Always return an array of matching elements for a CSS selector. If one single object is sent in, it return that same reference, and if several object references are sent in, it will return an array of those.

Example calls

$("#container input[type=text]");

$("#navigation a");

$("#news-list");

$("#container", "#navigation .important-item", "#content");

$(document.body);

$$(elementId)

The $$ method is used to get a quick reference to one element, just like document.getElementById. It will return a direct reference to the found DOM element, with all the DOMAssistant methods applied to it.

Contrary to the $ method, if the $$ method didn't return any match, it will throw an error if you try to call any method on it.

Parameters

Send in the id of the element you're looking for.

Return value

Returns a DOM reference.

Example calls

$$("container");

$$("navigation");

cssSelect(cssSelector)

Intended to be used on existing object references, to use a CSS selector to find children element(s) of the current object.

Parameters

cssSelector
Used to select elements. Required.

Return value

All calls return an array of element references.

Example calls

$(document).cssSelect(".mandatory");

$$(DOMElementReference).cssSelect(".important[type=test]");

elmsByClass(className, tag)

For getting elements based on their className. The method has a required parameter which is the desired className, and one optional if you want to limit the search to a certain tag.

Parameters

className
Class name to search for. Required.
tag
Only search elements that have this tag name. Optional.

Return value

All calls return an array of element references.

Example calls

$("#container").elmsByClass("mandatory");

$$("container").elmsByClass("external-link", "a");

elmsByAttribute(attr, attrVal, tag)

For getting elements based on if they have a certain attribute. You can also specify if that attribute should have a speific value and if you want to limit the search to a certain tag. Only the first parameter specifying the attribute is required.

Parameters

attr
Attribute name to look for. Required.
attrVal
Value that the desired attribute has to have. Optional. Use wildcard character ("*") if you want any attribute value but still want to specify tag.
tag
Only search elements that have this tag name. Optional.

Return value

All calls return an array of element references.

Example calls

$("#container").elmsByAttribute("href");

$$("container").elmsByAttribute("name", "subscription");

$$("container").elmsByAttribute("type", "text", "input");

elmsByTag(tag)

For getting elements based on their tag, i.e. what element it is. The method has one required parameter which is the name of the desired tag.

Return value

All calls return an array of element references.

Parameters

tag
Tag name to search for. Required.

Example calls

$$("container").elmsByTag("input");

each(functionRef)

For running a function on each of the items in a returned array element reference collection.

Return value

All calls return either a single element reference or an array of element references.

Parameters

functionRef
Function which will be called for each item in the array of elements it's called on. Can be an anonymous function or a function reference.

Example calls

$("#navigation a").each(function () {
// Do some JavaScript magic
});

first()

To get a reference to the first match in a collection.

Return value

Returns a reference to the first element match in a collection, with the DOMAssistant methods applied.

Parameters

None.

Example calls

$("#navigation a").first();

end()

To step one step up in the currect chaining context.

Return value

Returns a value to the previous element set in the chain.

Parameters

None.

Example calls

// Returns a reference to the a elements
$("#navigation a").create("span", null, true).end();

Get your copy