6
edits
Changes
JQuery
,additional information for using jQuery on a Web Page View. Checking that jQuery has been loaded on the page.
</pre>
You may encounter the situation where even after you have included the jQuery library in your code, possibly using the script above, you still recieve a '$ undefined' or 'jQuery undefined' error, when viewed in the browser console.
This means that the browser does not recognize the '$' or 'jQuery' reference, depending on which syntax you have used to access the jQuery object in your code.
This happens because the jQuery source code has not been loaded or completely loaded on the page when your script runs initially.
One way of rectifying this is to write your JavaScript code to repeatedly check to see if the jQuery library has been completely loaded and when that has happened you may then access the library using the jQuery object.
This can be implemented inserting the isjQueryLoaded function below in your code in addition to the script above:
<pre>
...
(function isjQueryLoaded(){
window.$ ? myScript() : setTimeout(isjQueryLoaded, 100);
})();
function myScript(){
//tasks to be completed when jQuery is loaded...
}
...
</pre>
[[Category:JavaScript]]