How do you just change the text “us-test” from the value of the link below, without having to replace the whole link, the current method i use replaces the whole link i guess that has to do with the function of .attr, i’m guessing i could achieve this by using .find or something else i really don’t have any clue on how to do it can someone help me on this thank’s.
$(document).ready(function(){
$("#box1").click(function(){
$("a.mylink").attr("href", "http://google.com");
});
$("#box2").click(function(){
$("a.mylinktwo").attr("href", "http://yahoo.com");
});
<a class="mylink" href="http://google.com/en/get.php?chrome=us-test">Test</a>
It depends on what you’re trying to achieve. I wouldn’t suggest complicating things too much, and if you can know before hand what URL to go to, replacing the whole URL would probably be best, and easiest to see what’s going on.
To replace parts of a string, the replace() method would help.
You can also pass a regular expression as the matching argument.