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

147
Views
Disable script tag in html file or change script tag type/src using javascript

I want to disable the script tag or if its possible to change script src or type in this script using javascript?

<script type="text/javascript" src="./1.js.download"></script>

I can't add id in this code.

please help and feel free to ask anything if you don't understand

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You can remove src from script tag like this:

s = document.querySelectorAll('script')
console.log(s[1])
s[1].setAttribute('src', '')
console.log(s[1])
<script type="text/javascript" src="./1.js.download"></script>

You will have maybe multiple scripts in your dom. then you have take a look which element it is and change the key from the collection. in this case the key was 1.

over 4 years ago · Santiago Trujillo Report

0

If you need to select specific script element you can get it by attribute like this:

let ok = document.querySelector('[src="./1.js.download"]');
//Then you can either change id or type:
ok.setAttribute('id', 'ok');
ok.setAttribute('type', 'module');

over 4 years ago · Santiago Trujillo Report

0

How about removing it altogether? The example is a simple function that get an element by the given selector and remove it. FYI if you don't want the <script> to actually load, then your'e out of luck. It'll be parsed as long as it's in the HTML, there's no way to avoid it from loading by JavaScript.

In the example there are 3 <script> tags and the target is in the middle. document.querySelector("script") will stop at the first match so you'll need a more specific selector. To target the second tag I used script:nth-of-type(2). You can verify success using by F12

const killTag = selector => document.querySelector(selector).remove();

killTag(`script:nth-of-type(2)`);
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>

<script type="text/javascript" src="./1.js.download"></script>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>

over 4 years ago · Santiago Trujillo 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!