Skip to content

Instantly share code, notes, and snippets.

@Draketheb4dass
Created November 27, 2019 04:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Draketheb4dass/1324615bfe24adc761db0e42129ee91e to your computer and use it in GitHub Desktop.
Save Draketheb4dass/1324615bfe24adc761db0e42129ee91e to your computer and use it in GitHub Desktop.
Change box color DOM manipulation
<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