Skip to content

Instantly share code, notes, and snippets.

@DannyMoerkerke
Created October 3, 2019 07:03
Show Gist options
  • Save DannyMoerkerke/2aae9b61f575e283588ec76d4ac6c990 to your computer and use it in GitHub Desktop.
Save DannyMoerkerke/2aae9b61f575e283588ec76d4ac6c990 to your computer and use it in GitHub Desktop.
Set multiple styles on an HTML element in one go
// 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