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

190
Views
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 answers
Answer question

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 Report

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 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!