Last active
February 11, 2024 20:33
-
-
Save dutchcelt/1abd49a692a8832a84f2fd42ed18c250 to your computer and use it in GitHub Desktop.
Use Object.assign to create new elements in vanilla JavaScript land.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 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