Created
February 14, 2017 01:41
-
-
Save dursk/0f0f4d96157fa964dcfd9c8d04650814 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=0f0f4d96157fa964dcfd9c8d04650814
This file contains 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> | |
<link href="style.css" rel="stylesheet"> | |
<title>JS-Function-Grid</title> | |
</head> | |
<body> | |
<h2>Fun on a grid</h2> | |
<div class="intro">You get a function: | |
<div class="code"> | |
setColor(row, column, color); | |
</div> | |
For a given row and column (both numbered from 0), it colors the corresponding cell. for example. try | |
<strong>setColor(2, 0, "purple");</strong> | |
</div> | |
<table id="t"> | |
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr> | |
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr> | |
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr> | |
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr> | |
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr> | |
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr> | |
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr> | |
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr> | |
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr> | |
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr> | |
</table> | |
</body> | |
</html> |
This file contains 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
{"enabledLibraries":["jquery"]} |
This file contains 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
function setColor(row, col, color) { | |
var cell = $("#t")[0].rows[row].cells[col]; | |
cell.style.backgroundColor = color; | |
} | |
setColor(2, 3, 'red'); | |
setColor(2, 6, 'red'); | |
setColor(5, 2, 'blue'); |
This file contains 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
#t { | |
border-collapse: collapse; | |
} | |
#t td { | |
border: 1px solid blue; | |
width: 2em; | |
height: 2em; | |
} | |
.intro { | |
font-family: arial; | |
line-height: 1.5em; | |
margin-bottom: 1em; | |
} | |
.code { | |
color: green; | |
font-family: monospace; | |
font-weight: bold; | |
} | |
div.code { | |
border: 1px solid green; | |
padding: 3px; | |
padding-left: 1em; | |
} | |
strong{ | |
color: green; | |
font-family: monospace; | |
font-weight: bold; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment