Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
<html>
<head>
<title>JS Example 1</title>
<style type="text/css">
*{
margin: 0px;
padding: 0px;
font-family: Helvetica;
}
#buttonOne{
color: pink;
background-color: yellow;
width: 60px;
text-align: center;
padding: 10px;
margin: 10px;
}
#buttonOne:hover{
background-color: gray;
}
#buttonTwo{
color: green;
background-color: yellow;
width: 60px;
text-align: center;
padding: 10px;
margin: 10px;
}
#buttonTwo:hover{
background-color: gray;
}
#box{
color: white;
width: 200px;
height: 150px;
text-align: center;
line-height: 30px;
margin-top: 30px;
margin-left: auto;
margin-right: auto;
background-color: pink;
}
</style>
<script type="text/javascript">
//Place js code inside "onload"
window.onload = function(){
//Check if page properly loaded
console.log("Page is Loaded!!!!");
//Initialize button variables
var buttonOne = document.getElementById('buttonOne');
var buttonTwo = document.getElementById('buttonTwo');
//Create the click event for button One
buttonOne.addEventListener('click', function(){
console.log("We clicked Button One!");
document.getElementById('box').style.backgroundColor = 'pink';
},false
);
//Create the click event for button Two
buttonTwo.addEventListener('click', function(){
console.log("We clicked Button Two!");
document.getElementById('box').style.backgroundColor = 'green';
},false
);
};
</script>
</head>
<body>
<div id="buttonOne">PINK</div>
<div id="buttonTwo">GREEN</div>
<div id="box"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment