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
.
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. |
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 must use kebab-case keys.
The created element.