0

I have some jQuery that shows/hides div #loading with a spinner inside of it depending on .ajaxStart or .ajaxStop. However it seems too general. Other links I click - or forms I try and submit - trigger the spinner. So is there a way to limit the code below to apply only to the links in my ul#infoContainer?

$(function() { $('#loading') .hide() // hide initially .ajaxStart(function(){ $(this).show(); }) .ajaxStop(function(){ $(this).hide(); }) }); 

1 Answer 1

1

Global Ajax events are just that, global.

If you want to attach the behavior just to $("ul#infoContainer a") then it might be better off using a click handler that does #loading show/hide.

Alternately, you could set global: false in the Ajax requests you don't want to trigger the global behavior. To me it makes more sense to explicitly define the behavior where I want rather than disable it where I don't, but that's just bias on my part.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.