Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
2 contributors

Users who have contributed to this file

@qdirks @chrisdavidmills
30 lines (26 sloc) 650 Bytes
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Random color example — event handler property</title>
<style>
button {
margin: 10px;
}
</style>
</head>
<body>
<button>Change color</button>
<script>
var btn = document.querySelector('button');
function random(number) {
return Math.floor(Math.random()*number);
}
function bgChange() {
var rndCol = 'rgb(' + random(255) + ',' + random(255) + ',' + random(255) + ')';
document.body.style.backgroundColor = rndCol;
}
btn.onclick = bgChange;
</script>
</body>
</html>
You can’t perform that action at this time.