jquery - Dynamically created image's onclick() not working -
I am trying to load all the images in a folder in a div (id = "wrap") but this The click function is not working. Why?
Below is my code.
& lt; Script & gt; $ (Document) .ready (function () {var folder = 'images / print / thumb /' post_data = {'folder': folder}; $ .post ('get_images.php', post_data, function (picture) {for (Var i = 0; i & lt; images.length; i ++) {var Tag = '& lt; img class = "thumb" src = "' + Folder + Picture [i] + '" / "'; $ ("$ (". "); $ (". Thumbs "). Click (function () {warning (this.id);});}); & lt; / script & gt; body; > It loads the image completely, with only the problem click event.
Ajax call back inside Try the incident of an error,
$ .post ('get_images.php', post_data, function (picture) {for (var i = 0; i & lt; images.length; I ++) {var tag = '& lt; $ (". Thumbs"). $ ("Thumb.") (Click "thumbs") ("thumbs" src = "' + folder + Picture [i] + '"/> function () {warning (this.id);});},' jason '); or the best way will be to use event delegation , $ ("# wrap"). ("Click", ". Thumb", function () {warning (this.id);});
Comments
Post a Comment