Skip to content

Instantly share code, notes, and snippets.

@victoriachuang
Last active July 12, 2016 16:12
Show Gist options
  • Save victoriachuang/8ab18121ce03d6b3015ac05ff58a4dd3 to your computer and use it in GitHub Desktop.
Save victoriachuang/8ab18121ce03d6b3015ac05ff58a4dd3 to your computer and use it in GitHub Desktop.
Change font size of an HTML document
var text = document.getElementById('text');
var small = document.getElementById('small');
var large = document.getElementById('large');
small.onclick = function() {
text.style.fontSize = '12px';
}
large.onclick = function() {
text.style.fontSize = '20px';
}
//
// refactored to reduce copy-and-paste
//
// function changeFont(size) {
// text.style.fontSize = size + 'px';
// }
//
// small.onclick = function() {
// changeFont(12);
// }
//
// large.onclick = function() {
// changeFont(20);
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment