I have created a dynamic div, along with the table…I want that when i click the image inside the div, it will give the the id of the div on which i have clicked…below is the code. Please any one point out where the mistake is…!? In the alert box i am unable to get the id of the div
following code creates the div
function create_newGrid() {
//create div for corresponding table
var tableDiv = $('<div/>').attr({ "id": "settingsDiv-tab" + nooftables });
var divImage = $('<img/>').attr({ "src": "settingsImage/settings.png", "onclick": "openTableSettings(this);" })
$(tableDiv).append(divImage);
// append grid to designer
$(document.getElementById("center")).append(tableDiv);
$(document.getElementById("center")).append(table);
}
following is the function that executes when a image in the div is clicked
function openTableSettings(div) {
alert($(div).attr("id"));
}
You are passing a reference to the img to
openTableSettings(). Use.closest()to get the div: