'How to launch function every time part of page reloads
i am making app in Django and i would like to launch function every time that i reload calendar. When user clicks arrows on the side of calendar it reloads division with calendar and shows new month. When user clicks on one of the days new content should show up (this is done by assigning content to each day using setAttribute("onclick", ...) function). Content showing works until i change month. From what i understand it is because i assign function to only existing DOM elements and not the new ones. I tried assigning it to new elements in various ways but it never worked. Is there some way to do it?
Month changing is done by ajax load function.
for (var x=0; x < days.length; x++) {
days[x].setAttribute("onclick", `setDay(
"${String(days[x].innerHTML)}",
"${(month[1].innerHTML)}"
)
`)}
$('#right').click(function () {
let mth = $('.month')[1].innerHTML.split(" ")
let month = parseInt(monthsObj[mth[0]])+1
let year = parseInt(mth[1])
if (month == 13) {
month = 1
year += 1
$('#newCal').html('').load(
"{% url 'calendarChange' monthNumber=4 yearNumber=2022 %}".replace("4", month).replace("2022", year)
);
} else {
$('#newCal').html('').load(
"{% url 'calendarChange' monthNumber=4 yearNumber=2022 %}".replace("4", month).replace("2022", year)
);
}
})
I tried putting that for cycle in function and putting it into ajax click. Ajax click then worked but for cycle didn't.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
