Jquery Basics Part-1 How to add jQuery to your website

July 4th, 2011 by Laeeq | 1 comment

Jquery is an awesome javascipt library, it’s help you for developing dazing web projects.

Actually jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript

How to add jQuery to your website

Installing

You can download jquery.js file form jquery.com.

<script type=”text/javascript” src=”jquery.js></script>

OR

Recommended

<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/

libs/jquery/1.3.0/jquery.min.js”></script>

Jquery Code

Generally used script run this when the HTML is all ready.

<script type=”text/javascript>

$(document).ready(function()

{

alert(‘Welcome phpzag.com Jquery Basic lesson ‘);

});

</script>

Similar as previous script.

<script type=”text/javascript>

$(function()

{

alert(‘Welcome phpzag.com Jquery Basic lessons ‘);

});

</script>

Run this when the whole page has been downloaded.

<script type=”text/javascript>

$(window).load(function()

{

alert(‘Loaded Whole Page including images)’);

});

</script>

jQuery Stucture

Here $ = jquery, selector is a DOM element and function execute a jquery fuction.

$(selector).function(parameters);

DOM – Document Object Model

Selectors

-> Select DOM elements eg: $(‘h1′) ,$(‘div’), $(‘li’)..

-> Select ID : $(‘#id_name’)

-> Select Class : $(‘.class_name’)

Working with Click() Event

Structure $(selector).click().

<script type=”text/javascript>

$(function()

{

$(‘#button_action‘).click(function()

{

alert(‘Button Clicked ‘);

});

$(‘.link_action‘).click(function()

{

alert(‘Link Clicked ‘);

});

});

</script>

<body>
<include type=’button‘ value=’BUTTON‘ id=’button_action‘/>
<a href=’#‘ class=’link_action‘>LINK</a>
</body>

Hide and Show With Click Event

Hiding and Showing the div tag.

<script type=”text/javascript>

$(function()

{

$(‘.hide_box’).click(function()

{

$(‘#box’).hide();

});

$(‘.show_box’).click(function()

{

$(‘#box’).show();

});

});

</script>

<body>
<a href=”#” class=”hide_box“>HIDE</a>
<a href=”#” class=”show_box“>SHOW</a>
<div id=”box“></div>
</body>

 

Jquery Basics Part-2

You can subscribe to PHPZAG.COM posts by Email

 

Related Topics:

  • Check if a string starts with http using Javascript
  • Use Google Hosted JQuery and Javascript Libraries in Your Projects
  • Hide and Show a Div Using Javascript
  • Detect Web Browser using Javascript
  • 11 Popular JavaScript Frameworks That Can Make You a Better Web Developer
  •  

     

    1. June 13th, 2012 at 17:56 | #1

      salutations from across the ocean. excellent blog I shall return for more.

    1. No trackbacks yet.