I'm trying to add to the end of specific links that contain a certain text.
In my code I found the specific links and changed the beginning of them leaving a variable from the original link. I need to add to the end of that variable. currently at the end of my code I use the append tag but it only adds to link text not the actual link. How can I do this or is there a better way?
$(document).ready(function () {
$("a[href^='http://www.1shoppingcart.com/']").each(function () {
this.href = this.href.replace(/^http:\/\/www\.1shoppingcart\.com\/SecureCart\/SecureCart.aspx/,
"http://www.1shoppingcart.com/SecureCart/Securecart.aspx/onclick = '_gaq.push(['_li开发者_如何学Gonk', 'http://www.1shoppingcart.com/SecureCart/Securecart.aspx/");
});
$('a[href*=1shoppingcart]').append("']); return false;'");
});
$('a[href*=1shoppingcart]').attr('href', function(i,v) {
return v + ']); return false;';
});
You could do it with another each
call:
$('a[href*=1shoppingcart]').each(function () {
this.href = this.href + ']); return false;';
}
That being said, do you really need to do this? It looks like you're adding Google Analytics clicks to links, and it seems like it'd be easy enough to just add a click
handler to all of your links (instead of modifying the href
attribute).
精彩评论