I have a trigger button with a class of 'next'and I have coded a jquery function as follows:
$(document).ready(function () {
$(".next").click(function (e) {
e.preventDefault();
console.log('got here');
var currentDate = new Date();
console.log(currentDate);
var dateElements = $(".date");
var nextDateElement = null;
dateElements.each(function () {
var date = new Date($(this).text());
if (date > currentDate) {
nextDateElement = $(this);
return false; // Exit the loop
}
});
if (nextDateElement) {
$('html, body').animate({
scrollTop: nextDateElement.offset().top
}, 'slow');
}
});
});
but I can't get it to work - or even display the console log. What might I be doing wrong?
Via Active questions tagged javascript - Stack Overflow https://ift.tt/YS51VwD
Comments
Post a Comment