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 renders as emphasized text, displaying the text oblique?
<strong> <pre> <em>
<p>Web development courses: <em>CoursesWeb.net</em></p>
Which CSS property defines the space between the element border and its content?
margin padding position
h3 {
  padding: 2px 0.2em;
}
Click on the method which returns the first element that matches a specified group of selectors.
getElementsByName() querySelector() querySelectorAll()
// gets first Div with class="cls", and shows its content
var elm = document.querySelector("div.cls");
alert(elm.innerHTML);
Indicate the PHP variable that contains data from a form sent with method="post".
$_SESSION $_GET $_POST
if(isset($_POST["field"])) {
  echo $_POST["field"];
}
jQuery Callback Functions

Last accessed pages

  1. Multiple Select Dropdown List with AJAX (19874)
  2. jQuery background position (5240)
  3. Add, Change, and Remove Attributes with jQuery (46245)
  4. Detect when ScrollBar reaches the bottom of the page (4366)
  5. Add /Delete rows in HTML table with JavaScript (4244)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (238)
  2. Read Excel file data in PHP - PhpExcelReader (83)
  3. PHP Unzipper - Extract Zip, Rar Archives (72)
  4. The Four Agreements (71)
  5. The Mastery of Love (60)