When the user clicks a link, I need to scroll up to the showemaildiv
and then fire a click event to open the email data. This works:
$(".showemaillink").click(function(e) {
e.preventDefault();
var emailid = $(this).attr('data-emailid');
var emaildiv = $(".showemaildiv[data-id='" + emailid + "']");
$('html, body').animate({
scrollTop: emaildiv.offset().top
}, 500);
emaildiv.click();
});
But to make it a little nicer, I'd like the email to expand after the animate so I'm using a callback. In this case, however, emaildiv.click()
is not working although the alert
is - what is wrong here?
$(".showemaillink").click(function(e) {
e.preventDefault();
var emailid = $(this).attr('data-emailid');
var emaildiv = $(".showemaildiv[data-id='" + emailid + "']");
$('html, body').animate({
scrollTop: emaildiv.offset().top
}, 500, function(){
emaildiv.click();
alert('callback fired');
}
);
});