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

192
Visualizações
removing similar html tags based on their inner text

I have 2 different script tags:

<script>//</script>
<script>//data</script>

I wanted to remove the first one. so I used the following:
$("script").filter(":contains('//')").remove();
but the line above removes both. How can i remove the first only.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

:contains means anywhere in the string

This will remove it if it ONLY contains "//"

$("script")
  .filter(function () { return this.textContent.trim() === "//" })
  .remove();

To remove the first script that has a // you can use .eq

$("script")
  .filter(":contains('//')")
  .eq(0)
  .remove();
about 4 years ago · Juan Pablo Isaza Relatório

0

.filter() method is return an array. so if you want to delete the first one you must select like an array.

$("script").filter(":contains('//')")[0].remove();
about 4 years ago · Juan Pablo Isaza 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