When you click on the
<a>
for a particular day, you execute the
dayClicked
function to update the calendar. But you don't prevent the default action, which is to navigate to the
href
, which reloads the page.
You could remove the
href
, which would prevent the navigation. But this would also affect the style of the link:
$("#days").append("<td class='day_active'><a onclick='dayClicked(" + month + "," + year + ");'>" + i + "</a></td>");
Or, you could add
return false;
after calling the
dayClicked
function:
$("#days").append("<td class='day_active'><a href='' onclick='dayClicked(" + month + "," + year + ");return false;'>" + i + "</a></td>");
Or, you could use jQuery delegated events:
function days(month, year) {
...
$("#days").append("<td class='day_active'><a href='' data-month='" + month + "' data-year='" + year + "'>" + i + "</a></td>");
}
};
$("#days").on("click", ".day_active a", function(evt){
evt.preventDefault();
var month = this.getAttribute("data-month");
var year = this.getAttribute("data-year");
days(month, year);
});