Kind: global class
Npmpackage:
- Markup
- new Markup()
- .get(selector, parent) ⇒
element
|HTMLCollection
- .removeChildren(_target)
- .applyToElements(arg)
This object contains utilities relateed to dom elements.
Import from ad-view
import { Markup } from 'ad-view'
Used to select elements.
Kind: static method of Markup
Returns: element
| HTMLCollection
- One single element if the selector is an id. With class name or tag name, it returns an HTML collection ( similiar to an array ).
Param | Type | Description |
---|---|---|
selector | string |
A string selector. It defaults to find the string as an id, or if the string starts with '#'. If starts with '.', it selects by class name. If wrapped with '<>', it selects by tag name. |
parent | element |
Optional parent element to get the element(s) from. Defaults to document. |
Example
// get element by its id called 'myId'
Markup.get('myId')
// same as above
Markup.get('#myId')
// get element by CSS classname 'myClass'
Markup.get('.myClass')
// get elements by tag name 'head'
Markup.get('<head>')
Removes all the children elements of an element
Kind: static method of Markup
Param | Type | Description |
---|---|---|
_target | element |
element to be targeted |
Apply a method to multiple elements. Currently assuming the method accepts element as the first argument, and a second argument as the setting.
Kind: static method of Markup
Param | Type | Description |
---|---|---|
arg | object |
See properties for more info: |
Properties
Name | Type | Description |
---|---|---|
arg.scope | object |
the scope of this |
arg.method | function |
the function to use |
arg.element | element | array |
the element(s) to apply the method to, can be a single element or an array |
arg.methodArg | string | number | array | object |
the argument to pass to the method function |
Example
var myElements = Markup.get( '.centered-blocks' );
Markup.applyToElements({
scope: Align,
method: Align.set,
elements: myElements,
methodArg: { x: Align.CENTER }
})