Reputation: 91
I am creating images with onclick
properties dynamically using jQuery
function create() {
divElem = $("<div class='row'>");
$('#bankList').append(divElem);
elem = $("<div class='col-sm-3', style='height:110px'>");
image = $("<img style=' max-width:90%'>");
var imageFile = '${pageContext.request.contextPath}/images/' + prop[j];
image.attr('src', imageFile);
image.attr('id',prop[j]);
image.on("click",submitForm(this.id));
elem.append(image);
divElem.prepend(elem);
}
Function create
is called on winodw.onload
and submit form
gets called onload
only. It should be called on clicking of image
Upvotes: 0
Views: 2064
Reputation: 171
you can add img onClick function on document
$(document).on('click', 'img', function() {
alert('Click on Image id: '+$(this).attr('id'));
});
Upvotes: 1