Reputation: 2674
On a search results page I have links. I would like to change the href of certain href from DispForm.aspx?ID=n
to AllItems.aspx?ID=n
but just for the href that have /R/I/P/
in the url.
I would like to use jQuery to change those href. Any suggestions?
<a title="" href="http://win/R/I/P/IL/F/DispForm.aspx?ID=n" id="S">link one</a>
<a title="" href="http://win/R/I/P/L/PN/DispForm.aspx?ID=n" id="S">link two</a>
<a title="" href="http://win/L/L/DispForm.aspx?ID=n" id="S">link three</a>
Upvotes: 1
Views: 3732
Reputation: 981
$('a').each(function() {
var href = $(this).attr('href');
if (href.indexOf("/R/I/P") >= 0) {
$(this).attr('href', new_href);
}
Upvotes: 0
Reputation: 18354
With this:
$("a[href*='/R/I/P/']").each(function(){
var href = $(this).attr('href').replace('DispForm.aspx?', 'AllItems.aspx?');
$(this).attr("href", href);
});
Upvotes: 2
Reputation: 165065
jQuery('a[href*="/R/I/P/"]').each(function(){
this.href = this.href.replace('DispForm', 'AllItems');
});
Upvotes: 4