1

I'm trying to do something like:

function xyz(id,name){

 $(this).spin();

 }

spin() is a jquery plugin function (spinner box), but however I want to access the id and name parameter of javascript into spin(). How can I do it without changing the spin() prototype?

sashkello
  • 17,306
  • 24
  • 81
  • 109
Nishant Jani
  • 1,965
  • 8
  • 30
  • 41

2 Answers2

2

Assuming that spin has local variables called id and name - you can't.

Scope is determined when the function is created, not when it is called.

The normal way to do this would be to pass the variables as arguments, but that would require spin to accept them in the first place. Since you can't change spin you can't do that.

The bad way to do this would be to use globals. If spin is competently written, it won't be using them so, again, you can't do that.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

If you're saying that you want to apply .spin() to the element with the id in that first parameter then do this:

function xyz(id,name){
    $("#" + id).spin();
}

That is, use a jQuery (CSS-style) selector to select the element by id, then apply .spin() to the resulting jQuery object.

nnnnnn
  • 147,572
  • 30
  • 200
  • 241
  • oh no , not doing something like this , actually i want to do a simple stepper but that stepper increment uniquely for each id – Nishant Jani Jul 23 '12 at 12:51
  • It seems to me your spin plugin should provide options to set increment independently. You mentioned in the question that you can't change spin, but why not? (I know you didn't write it, but you said you downloaded it so you have the source - or does the licence not allow any modifications?) – nnnnnn Jul 23 '12 at 12:55