I am rewriting a helper class which was originally built on top of Scriptaculous. I am moving to jQuery – however, I am stuck on a couple of lines, that I need help with (see below): Note: the javascript code is interpersed with php variables (the sigils being a dead give away)
Statement 1
'new Insertion.Before(\'' . $updateContainer . '\', new Element(\'div\', {\'id\': \'' . $updateContainer . '_loading\', \'class\': \'' . $spinnerClass .'\'})); $(\'' . $updateContainer . '_loading\').innerHTML="<h4>Loading ...</h4>";',
Statement 2
'$(\'' . $updateContainer . '_loading\').remove();'
I’ll assume that the
$updateContaineris ID of the HTML element that contains the loading message.Then, I’d write the Statement 1 like this:
And the second statement is:
If you have a lot of AJAX communication and need the ‘Loading’ often, it might be better to
hide()it so you can justshow()it later instead of creating the HTML again.Statement1 would be uset to create the loading element, Statement2 with
hide()instead ofremove()to hide it and Statement3 withshow()instead ofhide()to show it again.