Question

How to pass a variable into a method, here specifically the position(). All their examples use strings of fixed values.

I have two variables (varHorizontal, varVertical) both integers

$(this).position({
    "my": "center center",
    "at": varHorizontal varVertical,
    //also tried "at": varHorizontal+'px' varVertical+'px', 
    "of": $('#parentDiv')
}); 

I have looked for syntax rules and i have tried various combinations with '' etc, but no luck.

How can I pass variables into the method?

Was it helpful?

Solution

You need to concatenate them as a single string:

"at": varHorizontal + ' ' + varVertical,

OTHER TIPS

Use Array like this:

"at": [varHorizontal , varVertical],
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top