Reputation: 2674
I have some links in a page that i'd like to change from
<span id="lireArticle">
<a href="/Lists/ListeActualitesCarrousel/4_.000/DispForm.aspx?ID=4" class="action">Lire l'article</a>
</span>
<span id="lireArticle">
<a href="/Lists/ListeActualitesCarrousel/2_.000/DispForm.aspx?ID=4" class="action">Lire l'article</a>
</span>
<span id="lireArticle">
<a href="/Lists/ListeActualitesCarrousel/3_.000/DispForm.aspx?ID=4" class="action">Lire l'article</a>
</span>
to
<span id="lireArticle">
<a href="/Lists/ListeActualitesCarrousel/DispForm.aspx?ID=4" class="action">Lire l'article</a>
</span>
<span id="lireArticle">
<a href="/Lists/ListeActualitesCarrousel/DispForm.aspx?ID=4" class="action">Lire l'article</a>
</span>
<span id="lireArticle">
<a href="/Lists/ListeActualitesCarrousel/DispForm.aspx?ID=4" class="action">Lire l'article</a>
</span>
This works in Firefox, IE9, IE8 but not IE7!
it just changes the first link in IE7
jQuery("#lireArticle a").each(function(){
jQuery(this).attr('href',jQuery(this).attr('href').replace(/\/(\d)_.(\d{3})\//,'/'));
})
How can i get it to work in IE7?
Upvotes: 1
Views: 1141
Reputation: 14219
Oops made syntax error on previous post, updated. If you don't want to change the links by adding a class just use a different selector.
$('a[href^="/Lists/ListeActualitesCarrousel"]').each(function(){
var newURL = $(this).attr('href').replace(/\/(\d)_.(\d{3})\//,'/');
$(this).href(newURL);
});
Upvotes: -1
Reputation: 61812
The issue is you're using the same ID multiple times on the page. The ID of the element should be unique. Your code is finding the first instance of an element with the ID of "lireArticle" and changing all its a
's. I suggest using class=""
instead.
Markup:
<span class="lireArticle">
<a href="/Lists/ListeActualitesCarrousel/4_.000/DispForm.aspx?ID=4" class="action">Lire l'article</a>
</span>
<span class="lireArticle">
<a href="/Lists/ListeActualitesCarrousel/2_.000/DispForm.aspx?ID=4" class="action">Lire l'article</a>
</span>
<span class="lireArticle">
<a href="/Lists/ListeActualitesCarrousel/3_.000/DispForm.aspx?ID=4" class="action">Lire l'article</a>
</span>
JavaScript:
jQuery(".lireArticle a").each(function(){
jQuery(this).attr('href',jQuery(this).attr('href').replace(/\/(\d)_.(\d{3})\//,'/'));
})
Upvotes: 0
Reputation: 887459
You cannot have multiple elements with the same ID.
Use class=""
instead.
Upvotes: 2