I have two input boxes to put in height and width, and a button to make a table with Javascript. Now I want to make the color in each cell change as I hover over them. Preferably with jQuery.
function createTable(inRows, inCols) {
var inRows = document.getElementById('height').value;
var inCols = document.getElementById('length').value;
var body = document.getElementsByTagName("body")[0];
var tbl = document.createElement("table");
var tblBody = document.createElement("tbody");
for (var i = 0; i < inRows; i++) {
var row = document.createElement("tr");
for (var j = 0; j < inCols; j++) {
var cell = document.createElement("td");
row.appendChild(cell);
}
tblBody.appendChild(row);
}
tbl.appendChild(tblBody);
body.appendChild(tbl);
}
$(document).ready(function() {
$('td').hover(function() {
$(this).addClass('black');
});
});
In my feeble beginner mind, this looks right. But.. its not. Am I on the right track. And how do I make it happen?