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

178
Views
Change a script src with js

I want to change what js file an element uses at a certain year. Here is what I have so far. When I inspect the page the src changed but it did not affect the element as it's supposed to.

Thanks!

HTML:

<script id="element1" src="#"></script>
<script src="js/element-by-year.js"></script>

JS:

var yearly = document.getElementById("element1");

var refreshStatus = () => {
  // Get dates/time/hours
  const today = new Date();
  let year = today.getFullYear();

  if (year == 2022) {
    yearly.src ="js/change1.js";
  } 
  if (year == 2023) {
    yearly.src ="js/change2.js";
  }
}

// run when starting
refreshStatus();

// updates every day
setInterval(refreshStatus, 86400000);
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

To fix my problem I used functions instead of trying to change the src.

function element1 () {
    alert("It's 2022!");
}

function element2 () {
    alert("It's 2023!");
}

var refreshStatus = () => {
  const today = new Date();
  let year = today.getFullYear();

  if (year == 2022) {
    element1();
  } 
  if (year == 2023) {
    element2();
  }
}

refreshStatus();

setInterval(refreshStatus, 86400000);
about 4 years ago · Santiago Gelvez Report
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!