Edit this page

up.element 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.


Parameters

parent Element

The parent to which to attach the created element.

[position='beforeend'] string 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.
selector string

The CSS selector from which to create an element.

[attrs] Object optional

An object of attributes to set on the created element.

[attrs.text] Object optional

The text content of the created element.

[attrs.content] Object optional

The inner HTML of the created element.

[attrs.style] Object|string 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.

Return value

The created element.