jQuery Basics Part 1

JQuery is pretty handy but if you don’t use it often it can pain remembering the basics. In this post I’ll list some very simple starter snippets.

Function declaration
To make sure the DOM has finished loading before your code initialises, you can wrap your code in either of these 2 functions:

$("document").ready(function() { 
   insert code here 

Alternatively you can use the short cut version

   insert code here 

Linking to jQuery
Rather than hosting the jQuery scipts on your own site there are many advantages to using the Google content delivery network:

  • Improved speed, the content delivery network will usually be a lot quicker and more reliable that your hosting provider.
  • Many other websites use the content delivery network alongside the Google services such as Gmail and Google docs so there is a good chance your visitors may already have the jQuery or jQuery UI scripts cached by their browser.
  • Free and easy to use.

To make things even easier, http://scriptsrc.net is a handy site that supplies the script tags to many of the frameworks that are hosted on the Google content delivery network.

Published by

Mark Taylor

Web developer, based in Bourne, Lincolnshire, UK. builder of web applications, ASP.NET, Web Standards HTML, CSS & JavaScript. SQL Server & MySQL DB developer.

Leave a Reply

Your email address will not be published. Required fields are marked *