我有一个click事件处理程序,当我将元素添加到新内容时,它不会在特定选择器上触发。选择器是一个。如果我将选择器更改为'img',处理程序将触发所有图像,但不会触发我希望它触发的图像。我的所有代码似乎都在工作,我似乎无法解决这个问题。
//image to use throughout markup
var checkmark = '<img class="checkmark" src="mazihealth/My Images/checkmark2.jpeg" />'
//prepend image to existing content
$('.bjqs-caption').prepend(checkmark);
$('.bjqs-caption2').prepend(checkmark);
//click method on prepended image. works here.
$('.checkmark').click(function() {
var currimg = $('li.bjqs-slide').filter(function() {
return this.style['display'] == "list-item"}).find("img").data('score');
console.log(currimg);
});
//change images/content and prepend.
$('#cat').click(function() {
$(images.eq(0)).attr({
'src':"mazihealth/My Images/catBCS5.jpg",
}).siblings().html(catcontent.eq(0).html());
$('#image1').siblings().append('<p class="bjqs-caption2">'+ (cathover.eq(0).text()) + '</p>');
$(images.eq(1)).attr({
'src': "mazihealth/My Images/catbcs7.jpg",
}).siblings().text(catcontent.eq(1).text());
$('#image2').siblings().append('<p class="bjqs-caption2">'+ (cathover.eq(1).text()) + '</p>');
$(images.eq(2)).attr({
'src': "mazihealth/My Images/catBCS9.jpg",
}).siblings().text(catcontent.eq(2).text());
$('.bjqs-caption').prepend(checkmark);
$('.bjqs-caption2').prepend(checkmark);
});
//click event handler on prepended image not working after changing content/images.
$('.checkmark').click(function() {
var currimg = $('li.bjqs-slide').filter(function() {
return this.style['display'] == "list-item"}).find("img").data('score');
console.log(currimg);
});