For fun purposes, I wanted to create a 100x100 html table with javascript and use onmouseover to change color. It'd be like a simple way of painting, however when I change the onmouseover to a changeColor function, the parameter is a ClientX and ClientY position and not the html element.
function createTabel(){
var div = document.getElementById("paint");
var table = document.createElement("table");
table.style.border = "1px solid black";
for (var i = 0; i < 100; i++){
var row = document.createElement("tr");
for (var j = 0; j <100; j++){
var cell = document.createElement("td");
cell.onmouseover = changeColor;
cell.style.height = "3px";
cell.style.width = "3px";
cell.style.padding = "0";
cell.style.margin = "0";
row.appendChild(cell);
}
table.appendChild(row);
}
div.appendChild(table);
}
and the changeColor function:
function changeColor(cell){
var color = document.getElementById("color").value;
cell.style.backgroundColor = color;
}
How can I access the html element that caused the event without an id?
event.targetwill give you the dom element that caused the event.