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.
element = up.element.affix(document.body, '.klass')
element.parentElement // returns document.body
element.className // returns 'klass'
See up.element.createFromSelector()
for many more examples.
The parent to which to attach the created element.
The position of the new element in relation to parent
.
Can be one of the following values:
'beforebegin'
: Before parent
, as a new sibling.'afterbegin'
: Just inside parent
, before its first child.'beforeend'
: Just inside parent
, after its last child.'afterend'
: After parent
, as a new sibling.The CSS selector from which to create an element.
An object of attributes to set on the created element.
The text content of the created element.
The inner HTML of the created element.
An object of CSS properties that will be set as the inline style of the created element.
The given object may use kebab-case or camelCase keys.
The created element.