Created
August 24, 2016 16:29
-
-
Save cezarsmpio/50597ede97f790e75b38b6cc651e01fc to your computer and use it in GitHub Desktop.
Add CSS with object
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
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