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

141
Views
Replacing the script tag type and applying it

Is there any way to replace the script type with javascript only and execute it

this is an example script

<script id="myscript" src='myscript.js' type='text/template'></script>

i want to replace type with text/javascript i tried this code to replace it and it does replace the type but the script is not applied to the site.

<script>document.querySelector("#myscript").setAttribute("type","text/javascript");<script>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Make a new script instead, one with the proper type.

const existing = document.querySelector("#myscript");
const newScript = existing.cloneNode();
newScript.type = 'text/javascript';
existing.replaceWith(newScript);

Or just take the src of the existing one.

const existingSrc = document.querySelector("#myscript").src;
document.body.appendChild(document.createElement('script')).src = existingSrc;
about 4 years ago · Juan Pablo Isaza 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!