Hi }); Several

Hi Friends,In this blog i am going to tell about Jquery  and How to use jquery in web site development so lets start with a brief introduction of jquery. jQueryjQuery is a scripting language and it is a lightweight JavaScript library that simplifies programming with JavaScript. and it is client side scripting language.jQuery is a fast,and simple JavaScript library. with the help of jQuery we can change HTML document traversal and manipulation, we can also do event handling, Ajax, and animation much simpler with an easy-to-use API and it is easy to use as compare javascript. Advantages(Why we use jquery)There are several most important advantages over using the raw javascript. 1. jQuery is a cross-browser scripting lanquagege. 2. jQuery is very easy to use as compare to raw javascript 3. jQuery is extensible 4. It is a simplifies and has rich AJAX support scripting lanquagege. 5. jQuery has very large development community and it has many plugins. Example GridView template plugin. 6. Excellent documentation How to use jQuery in a web applicationTo use jQuery in any application so we need to Download the jQuery file from www.jQuery.com and give reference it in your application just like any other JavaScript file. ExampleIn this example i am going to Add a click event on a button using jquery and in it we don’t   need to worry about cross-browser issues,it is automatically handle by jquery. $(‘document’).ready(function () { $(‘#btnclick’).click(function () { alert(‘Hello jquery’); }); });  Several Points that we need to remember : 1. document.ready() function tell about that the DOM is fully loaded. 2. $ is a shortcut for jQuery ,in other words we can use the $ sign in place of jquery. 3. All three of the following syntaxes are equivalent: $(document).ready( handler ) jQuery().ready( handler ) (this is not recommended) $( handler ) There are several very important function that are use in jquery that is as below:- Difference between document.ready() and windows.load  $(document).ready(function()) :-This is very very important function or we can say that event of jquery. this event fires when the DOM is loaded and ready to be manipulated by script. it is fired before all the images, css etc.. are fully loaded. http://Scripts/jquery-1.11.2.js $(‘document’).ready(function () { $(‘#btnclick’).click(function () { alert(‘Hello jquery’); }); }); The above example is works because the click event of button is under the ready() function that means on that time DOM is fully loaded before this piece of code is executed so that javascript can get the button element in html DOM and adds the click on this button.   Now in above HTML we have remove the ready function and when we click the button we will not get the alert that is happen because jquery code is executed before HTML and at that time jquery can not find the button. $(window).load event :-This is also a very important function or we can say that event of jquery. this event fires when the DOM and all other content like css,images etc is fully loaded and it is fire after ready() event.Example:- In above code when we executed this first alert that will show  “DOM Loaded and ready” after that it will show  second alert box  “Window loaded after ready”. SelectorsSelector is use to get value of html elements there are several type of selector in jquery that is as follow:-1.Class Selector :- jQuery class selectors uses the JavaScript’s getElementsByClassName() method.SYNTAX$(‘.className’) Example:-$(‘.test’) // Selects all elements with class test$(‘.test,.test1’) // Selects all elements with class test or test1$(‘div.test,.test1’) // Selects div elements with class test and any element with class test1. Now  Lets take a example and see how jquery class selector will work.Selects all elements with class “test” and sets 1px solid black border.  Span 1

Div 1

Span 2

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

This is a test

In above example we can see that we set the border  on class test so that border set of that element whose class is test.  1.Id Selector :- jQuery Id selectors uses the JavaScript’s getElementsById() method.SYNTAX$(‘#IdName’) Example:-$(‘#test’) // Selects all elements with Id test$(‘#test,#test1’) // Selects all elements with Id test or test1$(‘div #test,#test1’) // Selects div elements with Id test and any element with Id test1. Now  Lets take a example and see how jquery Id selector will work.Selects all elements with Id “test” and sets 1px solid black border. Span 1

Div 1

Span 2

This is a test

In above example we can see that we set the border  on Id test so that border set of that element whose Id is test.  1.Attribute Selector :- jQuery attribute selectors uses the JavaScript’s element.getAttribute() method.Syntax $(‘attribute’)$(‘attribute=”value”‘)Example:-$(‘title’) // Selects all elements that have title attribute$(‘divtitle’) // Selects all div elements that have title attribute$(‘title=”divNew”‘) // Selects all elements that have title attribute value – divNew$(‘divtitle=”divNew”‘) // Selects all div elements that have title attribute value – divNew.  Selects all elements that have title attribute and sets 1px solid black border .

DIV 1

DIV 2

This is a paragraph

SAPN 1

SPAN 2 In above example we can see that we set the border  on that element  whose having title attribute. Each Function  This function is same as the looping like for loop ,while loop etc. in other word Each function is used to iterate values from a collection one by one. SYNTAX$(selecter).each(function (index, element) {   // logic}); Example :-$(‘li’).each(function (index, element) {    alert(index + ‘ : ‘ + $(element).text());}); In above example we loop through all the li   attribute and print the index with element text. Thanks for visit my blog hope this blog help you . Any though for further queries, feel free to place your valuable comments in the comments section below.