user472285
user472285

Reputation: 2674

change href jquery

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

Answers (4)

suren
suren

Reputation: 981

$('a').each(function() {
var href = $(this).attr('href');
if (href.indexOf("/R/I/P") >= 0) {
  $(this).attr('href', new_href);
}

Upvotes: 0

Edgar Villegas Alvarado
Edgar Villegas Alvarado

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

netbrain
netbrain

Reputation: 9304

this should do it!

http://jsfiddle.net/2VZMb/

Upvotes: 0

Phil
Phil

Reputation: 165065

jQuery('a[href*="/R/I/P/"]').each(function(){
    this.href = this.href.replace('DispForm', 'AllItems');
});

Upvotes: 4

Related Questions