views:

152

answers:

1

i have a number of dropdown controls and on the change event it kicks off ajax getJSON() calls. I have a div next to each dropdown with a spinner image as i want to display "loading . . " as some of the ajax calls are expensive.

Is there anyway i can just have one spinner div on the page and have the spinner move right next to the dropdown control that i just changed at that point. this way i can reuse one div instead of having them over and over on the page.

+1  A: 

You can create a spinner, or move it. It's easier to just destroy and create one on the ajax request I think...I have something like this when calling to a webservice to get something.

$(document.createElement("img"))
  .attr({ "src": "/Ajax/Spinner.gif" })
  .insertAfter(dropDownElementThatWasJustClicked);

In my case, I'm destroying everything inside that parent and replacing it when I get data back, so it destroys the spinner as part of that.

Nick Craver
i tried that but i dont see the image showing... do you need to add any additional line to have the image show or should .appendTo do it by itself. I am calling .appendTo on the id of the dropdown. is this correct?
ooo
ah . . looks like "insertAfter" worked perfectly . .
ooo
Yeah sorry about that, noticed on a re-read that .insertAfter() matched your situation much better, glad it's working now.
Nick Craver
what is the difference between insertafter() and appendto() ?? They sound the same
ooo
.AppendTo() say on a div, would stick it inside the div as the last element, .insertAfter() sticks it after the div element, as the next sibling. Here's the full list of manipulations with short descriptions: http://docs.jquery.com/Manipulation
Nick Craver