When you load a page, you need to make sure that all elements (HTML elements) have been loaded before making any change. This is because the main idea of jquery is to find elements in the document using CSS selectors.
We will get unexpected results if we apply those selectors before the browser has managed to load and process the entire HTML because some elements we are looking for may not be available yet.
There are 2 ways to do this:
- Put the script at the end of the body section of HTML document
- Use the jquery ready function
/// <reference path="jquery-3.2.1.js" /> $(document).ready(function() { // });
Note: We need to add the reference to jquery by dragging the jquery file into the editor area of the jquery file we are going to use jquery. It will be commented out but ASP.NET still process the line.
Advertisements