Skip to content

Instantly share code, notes, and snippets.

@cezarsmpio
Created August 24, 2016 16:29
Show Gist options
  • Save cezarsmpio/50597ede97f790e75b38b6cc651e01fc to your computer and use it in GitHub Desktop.
Save cezarsmpio/50597ede97f790e75b38b6cc651e01fc to your computer and use it in GitHub Desktop.
Add CSS with object
HTMLElement.prototype.css = function (style) {
for (let k in style) {
this.style[k] = style[k];
}
};
// Example 1
document.body.css({
backgroundColor: 'rgb(20,20,20)',
fontFamily: 'Arial, sans-serif',
fontSize: '16px'
});
// Example 2
var button = document.createElement('button');
button.css({
color: '#fff',
border: 0,
padding: '10px 15px'
});
// Example 3
var div = document.querySelector('.wrap');
div.css({
width: '1400px'
});
// Example 4
var container = document.getElementById('container');
button.addEventListener('click', e => {
container.css({
display: 'none'
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment