Log In | Register | September 23, 2019

Share
 

jQuery Programming - August 31, 2010

Using jQuery In Your Website

For jQuery to work the elements on the page must be ready for it to be manipulated and used.  Only once the DOM is loaded is when jQuery can then take effect. In order to start using jQuery we must include two things. One is the latest jQuery file which can be downloaded from the jQuery.com website, or also included directly from the Google code repository. The second thing you need to do is include a standard function that will prepare the browser for our jQuery commands.

The code is

$(document).ready(function() {
alert(‘You have successfully loaded jQuery’);
});

The code above is informing the browser that when the document is ready to run whatever is in between the curly brackets. In this case we used

alert(‘You have successfully loaded jQuery’);

which is a regular JavaScript function that issues a message for the user to see.

There is another way to start jQuery. The shorthand version that is as follows

$(function() {
alert(‘You have successfully loaded jQuery’);
});

The above code will handle exactly the same as the code described previously. It is really up to you to decide which way you prefer. Either way is perfectly acceptable.

Remember that all your code from now on will go within these functions. Without these functions your code will not run.

Post By: | FavoriteLoadingAdd to favorites

1 Comments

Kyle
Tuesday, August 31, 2010

This is a great Tutorial! Really good for starters.

Leave a Comment



Need Help? Ask a Question

Ask anything you want from how to questions to debug. We're here to help.

You Must Be Logged In To Post A Question.

Log In or Register