2

我有一个单击事件处理程序,当我将元素添加到新内容时,它不会在特定选择器上触发。选择器是一个 . 如果我将选择器更改为“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);
});
4

0 回答 0