Simple jquery passing a parameter via a link

Hi all,
im new to jquery.

I have this window that opens a modal:

http://bit.ly/1nwlkVW


How can I I pass a variable to the page that is opened from the link, so for example it opens ajax.html?id=[variable]

in normal js I would have just included it in the function call, like openmodal(12), but not sure how to do it in jquery

Thanks,
Stephen ForlanceAsked:
Who is Participating?
 
GaryCommented:
To the link add something like this

data-id="2"

In the jquery use

$.get('ajax.html?id='+$(this).data("id"), function(data){
0
 
GaryCommented:
You can add it directly in the js

$.get('ajax.html?id=somevar', function(data){

...unless there is more to it...?
0
 
Stephen ForlanceAuthor Commented:
Hi Gary, but how do I set somevar within the link?
0
 
GaryCommented:
Just change somevar to whatever it should be.
0
 
Stephen ForlanceAuthor Commented:
I think I need to explain what Im trying to do.

On the HTML there would be multiple links, each with a different variable.
Normally in JS I would do something like

<a href=#" onclick="somefunction(12)">a</a>

So the function somefunction would receive the variable 12, which I could then use to call the correct page.

How can I do this with jquery?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.