jquery

Can anyone help me to understand the following jquery ?
- $(document).ready - > what does it do ?
- $('#updater').click(UpdateNow);});  - > look for #updater element and insert a click event function, correct ?
- How does the following code work ?
$.get('/time', function (data) {
$('#clientTime').slideUp('fast', function () {
$('#clientTime').empty().append(data).slideDown();
});

<script type="text/javascript">
$(document).ready(function () {
$('#updater').click(UpdateNow);
});
function UpdateNow() {
$.get('/time', function (data) {
$('#clientTime').slideUp('fast', function () {
$('#clientTime').empty().append(data).slideDown();
});
});
}
</script>
AXISHKAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
Hi,
the $(document).ready is a jQuery wrapper for window.load and runs once the DOM is completely finished
(see http://learn.jquery.com/using-jquery-core/document-ready/)
$('#updater').click(UpdateNow);});  This selects the element with the ID "updater" and attaches / binds the function UpdateNow to the click event.

$.get('/time', function (data) {
 $('#clientTime').slideUp('fast', function () {
 $('#clientTime').empty().append(data).slideDown();
 });

Open in new window

The get function uses an AJAX call to get the content from the url "/time". Then it uses the slideUp animation (which reduces the height of an element with the id "clientTime" until it is "0" hence hidden) so that the content below the element slides up in the page. When this is complete it runs the anonymous function (the second parameter of the slideUp) which clears the content from the element, then appends the response from the get call and then calls the slideDown animation which "restores" the elements original size.

jQuery has a huge API documentation e.g.
http://api.jquery.com/slideup/

HTH
Rainer

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AXISHKAuthor Commented:
$('#clientTime').empty().append(data).

What is the purpose of .empty().

For (data), is it the data returned from $.get('/time') ??

Tks
Rainer JeschorCommented:
Hi,
the empty function removes all content from the element (mostly used with divs).
And you are right, data is the response content you received from the get call.
HTH
Rainer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.