Home Tutorial Jquery Separating custom code in different file

 
 

Separating custom code in different file
Posted on: July 24, 2010 at 12:00 AM
In this jQuery tutorial,We separates custom code in the separate custom java script file

Separating custom code  in different file

We can separate custom code in the separate custom java script file. In this example ,we put the jQuery script in a separate file , which will save with ".js" extension. This ".js" file have all the jQuery scripting .

jqCustom.html

<html>
<head>
<title>The jQuery Example</title>
<script type="text/javascript" src="jquery-1.4.2.js">
</script>

<script type="text/javascript" src="custom.js"></script>
</head>
<body>
<div id="mydiv">
Click here to see a dialogue box.
</div>
</body>
</html>

custom.js

$(document).ready(function() {
  $("div").click(function() {
  alert("Hello Friends!");
  });
});

We can include "custom.js" file as :

<script type="text/javascript" src="custom.js"></script>

OUTPUT :

Download Source Code

Click here to see demo

Related Tags for Separating custom code in different file: