new $Node()
Used to represent a node in better-dom
Methods
-
clone(deepCopy)
-
Clone element
Parameters:
Name Type Description deepCopyBoolean truewhen all children should also be cloned, otherwisefalseReturns:
A clone of the current element
- Type
- $Node
Example
ul.clone(true); // => clone of <ul> with all it's children ul.clone(false); // => clone of <ul> element ONLY
-
contains(element)
-
Check if an element is inside of the current context
Parameters:
Name Type Description element$Node Element to check
Returns:
trueif success andfalseotherwise- Type
- Boolean
Example
DOM.contains(DOM.find("body")); // => true DOM.find("body").contains(DOM); // => false -
find(selector)
-
Find the first matched element in the current context by a CSS selector
Parameters:
Name Type Description selectorString CSS selector
Returns:
The first matched element
- Type
- $Element
Example
var body = DOM.find("body"); // => <body> wrapper var foo = body.find(".foo"); // => the first element with class "foo" foo.find(".bar>span"); // => the first element that matches ".bar>span" -
findAll(selector)
-
Find all matched elements in the current context by a CSS selector
Parameters:
Name Type Description selectorString CSS selector
Returns:
An array of matched elements
- Type
- Array.<$Element>
Example
DOM.findAll("a"); // => all links in the document context.findAll("ol>li"); // => all <li> inside of <ol> -
fire(type [, detail])
-
Trigger an event of specific type with optional data
Parameters:
Name Type Argument Description typeString Type of event
detailObject <optional>
Custom event data
Returns:
trueif default event action was NOT prevented- Type
- Boolean
Example
link.fire("click"); // fire click event link.fire("my:event", {a: "b"}); // fire "my:event" with custom data -
get(name [, defaultValue])
-
Get property or attribute value by name
Parameters:
Name Type Argument Description nameString | Array Property or attribute name or array of names
defaultValueObject <optional>
Default value if returned is
nullReturns:
Value of property or attribute
- Type
- Object
Example
link.get("title"); // => property title link.get("data-custom"); // => custom attribute data-custom -
on(type [, options] [, args], callback)
-
Bind a DOM event listener
Parameters:
Name Type Argument Description typeString Event type
optionsObject | String <optional>
Event options object or css selector to match on
argsArray <optional>
Array of handler arguments to pass into the callback
callbackfunction Event listener callback
Returns:
Functor to cancel the listener
- Type
- function
Example
link.on("focus", function() { // do something on focus }); link.on("click", "i", function() { // do something on internal <i> click }); link.on("click", "span", ["currentTarget"], function(span) { // <span> is the element was clicked }); link.on("blur", {once: true}, function() { // event fired only once }); link.on("mousedown", {capture: true}, function() { // event fired on capturing phase }); -
set(name, value)
-
Set property/attribute value by name
Parameters:
Name Type Description nameString | Object | Array | function property/attribute name
valueString | function property/attribute value or functor
Returns:
Self
- Type
- $Node
Example
link.set("title", "mytitle"); // set title property link.set("data-custom", "foo"); // set custom attribute data-custom