Created
June 21, 2018 19:23
-
-
Save mmansion/be0c65e5f9301d4c551a339434d2a5da to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/norihap
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
body { | |
display: flex; | |
flex-wrap: wrap; | |
} | |
.grid-cell { | |
background: gray; | |
width: 50px; | |
height : 50px; | |
border: thin solid white; | |
} | |
.active { | |
background: red; | |
} | |
</style> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
// generate a grid, and add click handler | |
var body = document.body; | |
for(var i = 1; i <= 10; i++) { | |
for(var j = 1; j <= 10; j++) { | |
// create a cell element | |
var elem = document.createElement("div"); | |
elem.setAttribute("id", i*j); | |
elem.setAttribute("class", "grid-cell"); | |
elem.addEventListener("click", onClick); | |
document.body.appendChild(elem); | |
} | |
} | |
function onClick(e) { | |
e.target.classList.add("active"); | |
console.log(e.target.id); | |
} | |
</script> | |
<script id="jsbin-source-css" type="text/css">body { | |
display: flex; | |
flex-wrap: wrap; | |
} | |
.grid-cell { | |
background: gray; | |
width: 50px; | |
height : 50px; | |
border: thin solid white; | |
} | |
.active { | |
background: red; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// generate a grid, and add click handler | |
var body = document.body; | |
for(var i = 1; i <= 10; i++) { | |
for(var j = 1; j <= 10; j++) { | |
// create a cell element | |
var elem = document.createElement("div"); | |
elem.setAttribute("id", i*j); | |
elem.setAttribute("class", "grid-cell"); | |
elem.addEventListener("click", onClick); | |
document.body.appendChild(elem); | |
} | |
} | |
function onClick(e) { | |
e.target.classList.add("active"); | |
console.log(e.target.id); | |
}</script></body> | |
</html> |
This file contains hidden or 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
body { | |
display: flex; | |
flex-wrap: wrap; | |
} | |
.grid-cell { | |
background: gray; | |
width: 50px; | |
height : 50px; | |
border: thin solid white; | |
} | |
.active { | |
background: red; | |
} |
This file contains hidden or 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
// generate a grid, and add click handler | |
var body = document.body; | |
for(var i = 1; i <= 10; i++) { | |
for(var j = 1; j <= 10; j++) { | |
// create a cell element | |
var elem = document.createElement("div"); | |
elem.setAttribute("id", i*j); | |
elem.setAttribute("class", "grid-cell"); | |
elem.addEventListener("click", onClick); | |
document.body.appendChild(elem); | |
} | |
} | |
function onClick(e) { | |
e.target.classList.add("active"); | |
console.log(e.target.id); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment