Hi I am trying to write a web app using jQuery and I want to separate the JS code with HTML markup. Here is the code:
FILE: index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Customer Search</title>
<script src="js/jquery-1.9.1.min.js"></script>
</head>
<body>
...
<input type="button" id="button_batch_update" value="Save"/>
<script type="text/javascript" src="js/customer_search.js"></script>
</body>
FILE: customer_search.js
!function($){
$("#button_batch_update").click(function(e){
e.preventDefault();
alert("u clicked me!");
});
}(window.jQuery);
I copied the JS file code from bootstrap website (http://twitter.github.io/bootstrap/javascript.html). It works, but I don't really understand why the external JS file will work. Could someone help me out with this? Thanks!