Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda