Skip to content

Instantly share code, notes, and snippets.

@naoto-ogawa
Created October 10, 2016 08:32
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 naoto-ogawa/bb7f82490b33f766a13bd2255366663c to your computer and use it in GitHub Desktop.
Save naoto-ogawa/bb7f82490b33f766a13bd2255366663c to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<table id='t' border='10'>
<tr><td id='c00'>北海道</td><td id='c01'>5,400</td><tr>
<tr><td id='c10'>青森</td><td id='c11'>1,321</td></tr>
<tr><td id='c20'>岩手</td><td id='c21'>1,284</td></tr>
<tr><td id='c30'>宮城</td><td id='c31'>2,328</td></tr>
<tr><td id='c40'>秋田</td><td id='c41'>1,037</td></tr>
<tr><td id='c50'>山形</td><td id='c51'>1,131</td></tr>
</table>
</body>
<script>
document.querySelector("#t").onclick = function(e){
console.log("table");
console.log(e);
console.log(e.target);
};
for(var i=0; i<6 ; i++) {
for(var j=0; j<2 ; j++) {
document.querySelector("#c" + i + j).onclick =
(function(i,j){
return function(e){
console.log("cell (" + i + "," + j + ")" );
console.log(e);
console.log(e.target);
//e.stopPropagation();
};
})(i,j);
}
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment