Jquery Course

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 is used in <table> to create table header cell?
<thead> <th> <td>
<table><tr>
  <th>Title 1</th>
  <th>Title 2</th>
</tr></table>
Which CSS property sets the distance between lines?
line-height word-spacing margin
.some_class {
  line-height: 150%;
}
Which function opens a new browser window.
alert() confirm() open()
document.getElementById("id_button").onclick = function(){
  window.open("http://coursesweb.net/");
}
Indicate the PHP function that returns an array with names of the files and folders inside a directory.
mkdir() scandir() readdir()
$ar_dir = scandir("dir_name");
var_export($ar_dir);
jQuery Callback Functions

Last accessed pages

  1. JavaScript Chronometer / Stopwatch (7355)
  2. Node.js Move and Copy file (28421)
  3. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (141759)
  4. Upload Script for Gallery of Images and Audio files (9754)
  5. Ajax-PHP Chat Script (49484)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (483)
  2. CSS cursor property - Custom Cursors (81)
  3. The Mastery of Love (73)
  4. PHP-MySQL free course, online tutorials PHP MySQL code (64)
  5. CSS3 2D transforms (46)