Last active
August 1, 2020 02:16
-
-
Save Ifycode/6f188d80ead03344139c78f654e9210c to your computer and use it in GitHub Desktop.
Embed for Understanding Regular Function & Converting To Arrow Function Article index.js file - Js example 7
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
'use strict'; | |
function changeBackground(color) { | |
let container = document.getElementById('container'); | |
container.style.backgroundColor = color; | |
} | |
let redBtn = document.getElementById('redBtn'); | |
redBtn.onclick = function () { | |
changeBackground('red'); | |
} | |
let blueBtn = document.getElementById('blueBtn'); | |
blueBtn.onclick = function () { | |
changeBackground('blue'); | |
} | |
let yellowBtn = document.getElementById('yellowBtn'); | |
yellowBtn.onclick = function () { | |
changeBackground('yellow'); | |
} | |
/* In case you prefer to use addEVentListener | |
method: | |
let redBtn = document.getElementById('redBtn'); | |
redBtn.addEventListener('click', function() { | |
changeBackground('red'); | |
}); | |
let blueBtn = document.getElementById('blueBtn'); | |
blueBtn.addEventListener('click', function() { | |
changeBackground('blue'); | |
}); | |
let yellowBtn = document.getElementById('yellowBtn'); | |
yellowBtn.addEventListener('click', function() { | |
changeBackground('yellow'); | |
}); | |
*/ | |
/* | |
Output: | |
click on each button and body element's | |
background color will change to red, blue | |
and yellow respectively. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment