I'm trying to make a class that represents a point on a map with coordinates (as of now only in pixels), and an onclick function that displays the name and information about the location on the map, but I keep getting "undefined" as a value, and I feel like I'm missing something basic and it's driving me crazy. This is the code:
function Point (X, Y, N)
{
this.LX = X;
this.LY = Y;
this.name = N;
var pommap = document.getElementById("map");
var divic = document.createElement("div");
divic.style.position = "absolute";
divic.style.border = "2px solid black";
divic.style.height = "20px";
divic.style.width = "20px";
divic.style.top = X + "px";
divic.style.left = Y + "px";
divic.onclick = function()
{
var disp = document.createElement("div");
disp.style.position = "absolute";
disp.style.border = "1px dashed black";
disp.style.width = "200px";
disp.style.height = "100px";
disp.style.left = "1100px";
disp.style.top = "200px";
disp.innerHTML = this.name;
var pmap = document.getElementById("map");
pmap.appendChild(disp);
}
pommap.appendChild(divic);
}
The onclick function works, and my DIV gets drawn and appended correctly, but the only value inside is "undefined" string instead of the name I intended. This part I reckon is to blame, and I have no idea why:
disp.innerHTML = this.name;