// Prepare the table cell tableCell = document.createElement('td'); tableCell.textContent = currentDay.getDate(); var setDay = currentDay.getDate(); alert(setDay); tableCell.onclick = function() { setDate(prefix, setDay, currentDay.getMonth(), currentDay.getFullYear()) }