Monday, April 15, 2013

Call A Jquery function from outside of php/html file

Step 1:

Create a jquery function in a js file and save this with test.js name you can use your desired name as you want.

Example:


(function($){
  tile = function() {
alert("see it work")
  };
})(jQuery);
 

 Step 2:

create a php or html file at where you want to call function which is in test.js.

Example:

<!DOCTYPE html>
<html>
<head>
<title>HyperStudio Timeline</title>
 <script type="text/javascript" src="jquery-1.3.2.js"></script>
  <script type="text/javascript" src="test.js"></script>

<!--Here I used my function which i earlier defined in test.js file-->  <script type="text/javascript">
   $(document).ready(function(){
      tile();
    });
</script>
</head>
<body>
</body>
</html>


this is a simple way to call a jquery function from outsider js file.

Note: don't forget to include jquery-1.3.2.js file 'or' higher jquery file without this file these will not work.

0 comments:

Post a Comment