Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

213
Views
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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!