Reputation: 1411
So I have a URL like:
www.site.com/nice.html?menu=1
and I'm trying to find all links inside a div called.. ".page" and add "&menu=1" to them based on the menu parameter inside the url string.
I hope this makes sense. I'm going to create a jsfiddle.
Here is my JS so far.
$(".page a").each( function(){
//get page param with getmenu
var getmenu = "";
var attr = $(this).attr("href");
attr+"&menu="+getmenu;
});
Upvotes: 1
Views: 107
Reputation: 285
Check this. You have to reset the variable back to the href attribute. Alos you need to correct the name of your variable.
var gemenu = 0;
$(".page a").each( function(){
//get page param with getmenu
gemenu += 1;
var attr = $(this).attr("href");
attr += "&menu="+gemenu;
$(this).attr("href", attr);
});
Upvotes: 0
Reputation: 104775
How about:
$(".page a").each( function(){
//get page param with getmenu
var getmenu = location.href.split("?")[1];
var attr = $(this).attr("href");
$(this).attr("href", attr + "&" + getmenu);
});
Upvotes: 1