up.element.affix(parent, [position], selector, [attrs])
JavaScript function
Creates an element matching the given CSS selector and attaches it to the given parent element.
To create a detached element from a selector, see up.element.createFromSelector().
Use up.hello() to activate JavaScript behavior within the created element.
Example
element = up.element.affix(document.body, '.klass')
element.parentElement // returns document.body
element.className // returns 'klass'
See up.element.createFromSelector() for many more examples.
Position
parent
[position='beforeend']
optional
The position of the new element in relation to parent.
| Value | Insert position |
|---|---|
"beforebegin" |
Insert before reference, as a new sibling. |
"afterbegin" |
Prepend to reference, before its first child. |
"beforeend" |
Append to reference, after its last child. |
"afterend" |
Insert after reference, as a new sibling. |
Type: string
Element
selector
required
The CSS selector from which to create an element.
Type: string
[attrs]
[attrs.text]
General
[attrs.content]
[attrs.style]
optional
An object of CSS properties that will be set as the inline style of the created element. The given object must use kebab-case keys.
You may also pass a string with semicolon-separated styles.
Type: Object | string
Return value
The created element.
Type: Element