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 HTML5 tag can be used to embed an external application (SWF, PDF) in web page?
<mark> <embed> <canvas>
<embed src="flash_game.swf" width="450" height="350" />
Which CSS pseudo-element adds a special style to the first line of a text?
:first-letter :before :first-line
#id:first-line {
  font-weight: bold;
  color: blue;
}
Click on the window object property which gets or sets the URL of current page.
window.location window.self window.status
var url = window.location;
alert(url);
Indicate the PHP function used to get the contents of a file or page and store it into a string.
fopen() file_put_contents() file_get_contents()
$homepage = file_get_contents("http://coursesweb.net/");
echo $homepage;
jQuery Callback Functions

Last accessed pages

  1. SHA1 Encrypt data in JavaScript (35625)
  2. Output or Force Download MP3 with PHP (5825)
  3. Snap to Objects and Snap Align (2880)
  4. Highlight Images on click (6765)
  5. innerHTML and outerHTML to Get and Replace HTML content (30639)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (352)
  2. CSS cursor property - Custom Cursors (41)
  3. The Mastery of Love (39)
  4. PHP-MySQL free course, online tutorials PHP MySQL code (34)
  5. Read Excel file data in PHP - PhpExcelReader (31)