1

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; 
}); 

http://jsfiddle.net/kWAxe/

1
  • I can't figure out how to get the param of menu, and apply it into the each statement. Commented Aug 30, 2013 at 12:48

2 Answers 2

1

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);
}); 
Sign up to request clarification or add additional context in comments.

Comments

0

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);
}); 

http://jsfiddle.net/kWAxe/2/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.