i face a problem of jquery click function when i scroll down in list.
i'm confuse why this happened. i used following triggers below but not success.
i'm sending you code. this is code below. Please help me to sort out.
$(window).ready(function(){ $(".like").on("click", function(){
var id = $(this).attr('data');
// alert(id);
$.ajax({
url: "/stores/addLike",
type: 'GET',
data: {
id: id
},
error: function (data) {
console.log(data);
},
success: function (data) {
console.log(data);
if(data == "liked"){
alert('Sorry, you have already liked this beat.');
}else if(data == "notlogin"){
alert('Please login first to like a beat.');
window.location = "https://demo.amplifihub.com/login";
}else{
$(".likes"+id).text(data);
}
}
});
});
});
instead of $(".like").on("click", function(){ });
use $(document).on("click", ".like", function(){});
or use any static parent dom element
to preserve the DOM event. I believe you are generating .like class element on scroll ajax call.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.