We first look at a simple jQuery program.
To use jQuery, we need to include a source (src) link to a hosted jQuery file. Source file is usually put in between the <head> tag.
<!DOCTYPE html> <html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> $(document).ready(function() { $('#demo').html('Document is ready and loaded'); }); </script> </head> <body> <h4 id='demo'>Document Not Ready</h4> </body> </html>
If you visit Google Hosted Libraries, it provides an exact link like:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
To get the latest version, we can always remove the 10.2 from the link:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
This is also an advantage of using hosted code from Google as it provides a simple way to always use the latest jQuery code.