Home  >  jQuery

Example of callbacks in jQuery

December 12, 2012
Callbacks function is used in jQuery for multipurpose task at one time. Callbacks function is executed after current task is done. Callback function is created in another function.
Syntax - $(selector).show(speed,callback);
Example
<!DOCTYPE html>
<html>
<head>
<script src="jquery.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
 $("p").hide("slow",function(){
          $('#callBack').show('slow');
    });
  });
});
</script>
</head>
<body>
<button>Hide</button>
<p>This is callback example</p>
<div id="callBack" style="display:none">This is callback function</div>
</body></html>
According to example when click on hide button, hide() function is executed and p element is hide, after hide function executed show function is executed and show the div element. Callback function is declare in hide function.
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us