In this section, we will create our first jQuery application called "Hello World jQuery". This application will simply display Hello World !! (display due to jQuery)
message in the browser.
After completing this example, you will be able to include the jQuery library in your application and use it to perform simple functions.
Let's start developing the Hello World application in jQuery.
Setting up jQuery
Click on the following link to open a page containing the jQuery library script. This file is around 70KB. Save this as "jquery-1.4.2.js". Now we are ready to use jQuery inside your HTML page.
Hello World Example (HelloWorld.html)
<html>
|
Description of the Program
The first and most important thing is to include the jQuery library as:
<script type="text/javascript" src="jquery-1.4.2.js"></script>
If you use the above tag as it is, you need to save the "jquery-1.4.2.js" in the same folder where you saved your HTML page. You can also save it in another folder but, in that case, you need to provide the relative path.
Let's look at the code precisely:
<script type="text/javascript">
|
To use jQuery script, we write it inside the <script> tag. The below code checks whether the page loading is finished (DOM elements are ready or fully loaded), and if page loading is finished, it executes the code in the block.
$(document).ready(function(){
// Your code here
});
The code given below sets the message in the div with id "flag" in HTML form:
$("#flag").html("Hello World !! (display due to jQuery)");
Comments
Post a Comment