Skip to content

Instantly share code, notes, and snippets.

@oddurs
Created June 28, 2014 07:22
Show Gist options
  • Save oddurs/9e9c5f65f7962e40ac24 to your computer and use it in GitHub Desktop.
Save oddurs/9e9c5f65f7962e40ac24 to your computer and use it in GitHub Desktop.
#box {
width: 50px;
height: 50px;
background: blue;
top: 150px;
left: 10px;
}
.normal {
background-color: white;
color: black;
}
.changed {
background-color: black;
color: white;
}
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Event handlers lesson" />
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body class="normal">
<h1>Hello, events</h1>
<p>la di da</p>
<button>Normal</button><button>Changed</button>
</body>
</html>
(function() {
var button = document.getElementsByTagName("button");
for (var i = 0, len = button.length; i < len; i++) {
button[i].onclick = function() {
var className = this.innerHTML.toLowerCase();
document.body.className = className;
};
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment