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.
<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:
<table><tr> <th>Title 1</th> <th>Title 2</th> </tr></table>
.some_class { line-height: 150%; }
document.getElementById("id_button").onclick = function(){ window.open("http://coursesweb.net/"); }
$ar_dir = scandir("dir_name"); var_export($ar_dir);