Created
October 3, 2019 07:03
-
-
Save DannyMoerkerke/2aae9b61f575e283588ec76d4ac6c990 to your computer and use it in GitHub Desktop.
Set multiple styles on an HTML element in one go
This file contains 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
// select an element to style | |
const container = document.querySelector('#container'); | |
// this is not ideal... | |
container.style.width = '400px;'; | |
container.style.height = '300px'; | |
container.style.top = '0'; | |
container.style.left = '50%'; | |
// let's assign all styles in one go! | |
Object.assign(container.style, { | |
width: '400px', | |
height: '300px', | |
top: 0, | |
left: '50%' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment