My question is why I cant use $(this) the jQuery selector in ajax loaded content here is my code:
$('.commentsDiv').css({'opacity': '0'});
var loadTheComments = $('.commentsDiv').load($homeUrl+'trailer-comments/'+$trailerID,function(){
$('.targetDiv').hide();
$('.showSingle').click(function(e){
e.preventDefault();
$('#div'+$(this).attr('target')).slideToggle();
});
var commentsReplyLink = $('.commentReplyLink');
commentsReplyLink.click((e)=>{
e.preventDefault();
commentsReplyLink.each(()=>{
var $self = $(this);
var $addedBy = $self.attr('data-value');
var $commentID = $self.attr('data-id');
$('html,body').animate({
scrollTop: $(".post-comment-form").offset().top},
'slow');
$('#commentReplyDiv').css({
display: 'block',
});
console.log('added by: '+$addedBy+' comment id: '+$commentID);
$('#replyToCommentInput').val($addedBy);
$('#replyToCommentInput').attr('comment-id', $commentID);
});
});
}).animate({opacity:'1'}, 3500, () => {});
im trying to get the comment-id attribute from the hyperlink that looks like that:
<a class="commentReplyLink" data-id="14" data-value="Reply to #14" href=""><em>Reply</em></a>
but when is clicked on that hyperlink im getting this in the Console.log() .. :
added by: undefined comment id: undefined