Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7511699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:37:52+00:00 2026-05-29T23:37:52+00:00

This code replaces only parts of a string for the first link, but how

  • 0

This code replaces only parts of a string for the first link, but how do I modify this code to take advantage of the click and replace parts of the string for the other links as well, the other links will have different text e.g for “ca-test” it could be anything you want I just want to get this working thanks!

$("#box1").click(function(){
var url = $('.mylink').attr('href')
url = url.replace('us-test', 'replaced-text')
$('.mylink').attr('href', url) 
 });  

<a class="mylink" href="http://google.com/en/get.php?chrome=us-test">Test</a> 
<a class="mylink2" href="http://google.com/en/get.php?chrome=ca-test">Test</a>  
<a class="mylink3" href="http://google.com/en/get.php?chrome=tk-test">Test</a>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:37:54+00:00Added an answer on May 29, 2026 at 11:37 pm

    . it not the best solution since it not clear how your page function but maybe it useful for you

     $("#box1").click(function(){
        var rep1=new Array(".mylink",".mylink2",".mylink3");
        var rep2=new Array("us-test","ca-test","tk-test");
        var rep3=new Array("us-test1new","ca-test1new","tk-test1new");
        replace(rep1, rep2, rep3);
         });  
    
    
        function replace(a, b, c)
    
        {
        for(var i=0; i < a.length;  i++)
        {
        var url = $(a[i]).attr('href');
        url = url.replace(b[i], c[i]);
        $(a[i]).attr('href', url);
         }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code should clear the textarea when there is only spaces and breaklines but
I'm trying to use this code to replace spaces with _, it works for
Help me replace this code, both me and Resharper don't like it: <table width=100%>
foo\r\nbar.replace(/(foo).+/m, bar) Hello. I can not understand why this code does not replace foo
i got this code $current_path = str_replace('\', '/', getcwd()); //c://xampp/htdoc Why it fail replace
I've got the following code: Regex.Replace(text, words.ToString(), <dfn title=\ + this.FindDefinition($0) + \>$0</dfn>, RegexOptions.IgnoreCase
I have a bit of code that looks like this: text = reg.Replace(text, new
I have the following C# which simply replaces parts of the input string that
Given a string like this: <a href=http://blah.com/foo/blah>This is the foo link</a> ... and a
I am trying to replace/modify a part of string in a python file from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.