, , , :
HTML:
<a title="Relevance" id="link1" href="http://www.url.com/search/1/3/5/1/4/0">my link</a>
JQuery
$('#link1').click(function(){
var url = this.href;
var finalSlashLength = url.substring(url.lastIndexOf('/') + 1).length;
var newUrl = url.substring(0, url.length - finalSlashLength);
newUrl += 'some new value';
window.location.href = newUrl;
});
:
http://jsfiddle.net/QRpYC/2/
EDIT:
As you mention in the comments, the markup is generated dynamically - you can easily find links based on other parameters. The first thing I would be looking for is to sit in a shared container, like div, etc.? Find the parent with the name, class, or identifier attribute and use it as a selector.
For example, if the markup looks like this:
<div id="searchLinks">
<a title="Relevance" href="http://www.url.com/search/1/3/5/1/4/0">my link</a>
<a title="SomeLink" href="http://www.url.com/search/1/3/5/1/4/1">my link</a>
</div>
Then you can select them using:
$('div#searchLinks > a').click(function(){....});
source
share