I am trying to change the background color of the selected date in my calendar. In my below code, it highlights all the clicked date, how can I only highlight the last clicked date?
dayClick: function (day){
var mydate = new Date(this[0].getAttribute("data-date"));
var dateArray = mydate.toDateString().split(" ");
document.querySelectorAll(".calendar-mobile p")[0].innerHTML = j_monthNames[mydate.getMonth()] + " " + mydate.getDate() + "日" + "(" + j_dayNames[dateArray[0].toLocaleLowerCase()] + ")";
document.body.classList.remove("calendar-open");
$month = '' + (mydate.getMonth() + 1);
$day = '' + mydate.getDate();
$year = mydate.getFullYear();
if ($month.length < 2) $month = '0' + $month;
if ($day.length < 2) $day = '0' + $day;
$dates = [$year, $month, $day].join('-');
$('[data-date='+$dates+']').css({"color": "red", "backgroundColor": "yellow",});
},