Created
November 27, 2019 04:03
-
-
Save Draketheb4dass/1324615bfe24adc761db0e42129ee91e to your computer and use it in GitHub Desktop.
Change box color DOM manipulation
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
<style> | |
.red-square { | |
width: 100px; | |
height: 100px; | |
background-color: crimson | |
} | |
</style> | |
<div class="red-square"></div> | |
<button onclick="changeColor('gray')">change</button> | |
<button onclick="changeColor('red')">red</button> | |
<button onclick="changeColor('blue')">blue</button> | |
<button onclick="changeColor('black')">black</button> | |
<button onclick="changeColor('yellow')">Yellow</button> | |
<script> | |
const redSquare = document.querySelector('.red-square'); | |
redSquare.style.marginLeft = '500px' | |
redSquare.style.backgroundColor = 'limegreen' | |
function changeColor(color) { | |
redSquare.style.backgroundColor = color | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment