Skip to content

Instantly share code, notes, and snippets.

@dutchcelt
Last active February 11, 2024 20:33
Show Gist options
  • Select an option

  • Save dutchcelt/1abd49a692a8832a84f2fd42ed18c250 to your computer and use it in GitHub Desktop.

Select an option

Save dutchcelt/1abd49a692a8832a84f2fd42ed18c250 to your computer and use it in GitHub Desktop.
Use Object.assign to create new elements in vanilla JavaScript land.
/* https://twitter.com/jh3yy/status/1564926775620243456
* This ๐Ÿ‘‡ */
const ELEMENT = Object.assign(
document.createElement('button'),
{
className: 'fab',
popUp: 'manual',
style: '--index: 1;',
innerHTML: `
<i class="material-icons">add</i>
`
}
)
/* Instead of this ๐Ÿ‘‡
const ELEMENT = document.createElement('button')
ELEMENT.className = 'fab'
ELEMENT.setAttribute('popup', 'auto')
ELEMENT.style = "--index: 1;"
ELEMENT.innerHTML = '<i class="material-icons">add</i>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment