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

157
Views
remove "?" from all anchor text

I am trying to remove the ? character from all anchor href values with Javascript. For example, there are many URLs like this:

<a href="https://example.com/something/?">my anchor</a>

I tried this but getting the error index of is not a function

var url = jQuery("a");
var a = url.indexOf("?");
var b =  url.substring(a);
var c = url.replace(b,"");
url = c;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To achieve this you can provide a function to prop() which runs against all elements in the collection. In the function you can accept the current href value as an argument then use replace() to remove the ? characters:

$('a').prop('href', (i, h) => h.replace(/\?/g, ''));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="https://example.com/something/?">my anchor 1</a>
<a href="https://example.com/somethingelse/?">my anchor 2</a>
<a href="https://example.com/?something">my anchor 2</a>

Note that this will replace all instances of ? from anywhere in the href value. If you only want to remove it from the end of the string change the regex to /\?$/g

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!