I have an image in a div
:
<div id="elem-0" onClick="updateSelectedElement(0);">
<img src="#" id="elem-1" onClick="updateSelectedElement(1);">
</div>
and I'm going to delete this image when it's selected. I detect selecting by listening to an onclick()
of each element:
function updateSelectedElement(id) {
// select the clicked element
SelectedElement = "#elem-" + id;
}
Note: IDs are created dynamically (I simplify my problem in this example)
My problem is that when I click on an image to select it, updateSelectedElement()
of image is called first and then updateSelectedElement()
of div. The final value of SelectedElement
will be "0" and I can't select that inner element (to modify or delete it, for example)
I have tried to save the max number of IDs, but it doesn't work, because if I have some other elements with lower IDs, I can't select them anymore.