I have the following loading image:
<img id="loading" src="loading.gif" />
To show/hide it during an AJAX call, I have several solutions. For example, I can hide it by adding a class which corresponds to a CSS style:
$('#loading').addClass('hidden');
.hidden { display: none; }
Alternatively, I can use jQuery .show()
and .hide()
. In this particular example, the latter approach is less verbose.
What scenarios benefit from adding CSS 'on the fly'? I've been reading into 'Unobtrusive JavaScript' which recommends injecting all JS into the DOM using jQuery at $(document).ready().
Is there a best practices approach which cleanly separates CSS and jQuery in a similar manner?