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

187
Views
Hide specific text on load but use same text to identify element for click event

I want to hide links containing "NOSP" when clicking a No Spoiler button, but also hide that "NOSP" text by default.

Using jQuery this is what I've tried so far:

$("button").click(function(){
$("a:contains('NOSP')").hide();
});

$("a:contains('NOSP')").each(function(){
$(this).text($(this).text().replace('NOSP',''))
});
a { display: table; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<button>Hide spoilers</button>

<a href="#">Full match</a>
<a href="#">All goals NOSP</a>
<a href="#">Highlights</a>
<a href="#">Highlights</a>
<a href="#">Highlights NOSP</a>

(also a jsfiddle)

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

0

You can pre-process all this with $(document).ready and add a className to each NOSP link to reference it later, and at the same time remove that string from the link text. Note: just in case there is some word out there with NOSP in it, I broke the text into an array and used array.includes(targ) to find it.

$(document).ready(function() {
      $("a").each(function() {
        let t = $(this).text().split(" ")
        if (t.includes('*')) {
          t.splice(t.indexOf('*'), 1)
          $(this).addClass('nosp').text(t.join(" "))
        }
      })
      $("button").click(function() {
        $("a.nosp").hide();
      });
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button>Hide spoilers</button>

<a href="#">Full match</a>
<a href="#">All goals *</a>
<a href="#">Highlights</a>
<a href="#">Highlights</a>
<a href="#">Highlights *</a>

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!