I created a dynamic div along with a table ... I want that when I click on the image inside the div, it will give out the identifier of the div that I clicked on ... the code is below, Please mark where the error is ...!? In the warning window, I cannot get the div id
The following code creates a div
function create_newGrid() {
var tableDiv = $('<div/>').attr({ "id": "settingsDiv-tab" + nooftables });
var divImage = $('<img/>').attr({ "src": "settingsImage/settings.png", "onclick": "openTableSettings(this);" })
$(tableDiv).append(divImage);
$(document.getElementById("center")).append(tableDiv);
$(document.getElementById("center")).append(table);
}
the next is the function that is executed when an image is clicked on an element
function openTableSettings(div) {
alert($(div).attr("id"));
}
source
share