Including the jQuery Library
That is jQuery code. You'll first need to make sure the jQuery library is loaded. If you don't host the library file yourself, you can hotlink one from the jQuery CDN:
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
You can do this within the <head>
section, but it's fine as long as it's loaded before your jQuery code.
Further reading:
Placing Your Code in the Page
Place your code inside <script>
tags. It can be inserted anywhere within either <head>
or <body>
. If you place it before the <input>
and <tr>
tags (as referenced in your code), you have to use $(document).ready()
to make sure those elements are present before the code is run:
$(document).ready(function() {
// put your jQuery code here.
});
If you want your page content to be loaded as soon as possible, you might want to place it as close as the </body>
close tag as possible. But another common practice is to place all JavaScript code in the <head>
section. This is your choice, based on your coding style and needs.
Suggestion: Instead of embedding JS/jQuery code directly into an HTML page, consider placing the code in a separate .js file. This will allow you to reuse the same code on other pages:
<script src="/path/to/your/code.js"></script>
Further reading: