Callback Functions are functions that are added as arguments to other function.
JavaScript instructions are executed line by line, very fast. With effects, the next line of code can be run even though the effect is not finished. This can create errors. To prevent this, you can use a callback function.
A callback function is executed after the current effect is completely finished.
In jQuery, the callback functions are used alot in animation effects.

- Example (see the comments in code):
<button id="test">Click</button>
<script type="text/javascript">
// when click on the "test" button, it is executed a callback function (as parameter to click() method)
$('#test').click( function() {
 // this function hides the clicked element, then displays an alert message
 // the alert() instruction it is added into an anonymous callback function (passed as seccond parameter)
 $(this).hide("slow", function(){
 alert('Hi :)');
 });
});
</script>
- Demo:
• To see the difference, here is the same example, but with the alert() instruction added after the hide() method (not into a callback function).
<button id="test">Click</button>
<script type="text/javascript">
// when click on the "test" button, it is executed a callback function (as parameter to click() method)
$('#test').click( function() {
 // this function hides the clicked element, and displays an alert message (almost in the same time)
 $(this).hide("slow");
 alert('Hi :)');
});
</script>
- Demo:

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which tag adds an image in web page?
<div> <img> <span>
<img src="http://coursesweb.net/imgs/webcourses.gif" width="191" height="63" alt="Courses-Web" />
Which of these CSS codes displays the text oblique?
font-style: italic; text-decoration: underline; font-weight: 500;
#id {
  font-style: italic;
}
Click on the jQuery function used to hide with animation a HTML element.
click() hide() show()
$(document).ready(function() {
  $(".a_class").click(function(){ $(this).hide("slow"); });
});
Click on the correctly defined function in PHP.
fname function() {} function fname() {} function $fname() {};
function fname($a, $b) {
  echo $a * $b;
}
jQuery Callback Functions

Last accessed pages

  1. The Rise Of Atlantis (12130)
  2. innerHTML in PHP (6400)
  3. Bubbles3 (52204)
  4. Raft Wars (2274)
  5. PHP MySQL - UPDATE (3055)

Popular pages this month

  1. Flash Games - Free online Games (1930)
  2. Qwop (1474)
  3. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (1331)
  4. Tunnel Rush (1259)
  5. Drag Racer V3 (979)