Thursday 28 December 2017

html - Click event not working on objects added dynamically in jQuery





I've a HTML page where I'm adding an icon file to DIVs dynamically.
This image serves as close icon and has a predefined class, say, 'close'. To this class
I've attached the click event
like



$('.close').click(function({


alert('You chose to delete this
image');
});


this
works fine for the script that is loaded on page load. However, when I attach the same
icon to other DIVs, the click event doesn't seem to trigger. There's no error in
firebug. I don't know what's wrong!


class="post-text" itemprop="text">
class="normal">Answer



Delegate
on document or the closest static
element



$(document).on('click',
'.close', function () {
alert("You chose to delete this
image");

});


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...