>
How jQuery Works
Welcome, Guest

by NeerajRawat on Thursday, 13 November 2008
How jQuery Works


The Basics This is a basic tutorial, designed to help you get started using jQuery. If you don't have a test page setup yet, start by creating a new HTML page with the following contents: // Your code goes here jQuery Edit the src attribute in the script tag to point to your copy of jquery.js. For example, if jquery.js is in the same directory as your HTML file, you can use: The first thing that most Javascript programmers end up doing is adding some code to their program, similar to this: window.onload = function(){ alert("welcome in suripages") } Inside of which is the code that you want to run right when the page is loaded. Problematically, however, the Javascript code isn't run until all images are finished downloading (this includes banner ads). The reason for using window.onload in the first place is due to the fact that the HTML 'document' isn't finished loading yet, when you first try to run your code. To circumvent both problems, jQuery has a simple statement that checks the document and waits until it's ready to be manipulated, known as the ready event: $(document).ready(function(){}); $(document).ready(function(){ // Your code here }); The remaining jQuery examples will need to be placed inside the ready event so that they are executed when the document is ready to be worked on. Add the next section of code: $("a").click(function(event){ alert("Thanks for visiting!"); }); Save your HTML file and reload the test page in your browser. Clicking the link on the page should make a browser's alert pop-up, before leaving to go to the main jQuery page. For click and most other events, you can prevent the default behaviour - here, following the link to jquery.com - by calling event.preventDefault() in the event handler: $("a").click(function(event){ alert("As you can see, the link no longer took you to jquery.com"); event.preventDefault(); }); Adding a CSS Class Another common task is adding (or removing) a CSS (Cascading Style Sheet) class. First,you were to add some style information into the header of your script, like this: a.test { font-weight: bold; } and then added the addClass call - $("a").addClass("test"); all your a elements would now be bold. To remove the class, you'd use removeClass $("a").removeClass("test"); * CSS allows multiple classes to be added to an element.) Special Effects In jQuery, a couple of handy effects are provided, to really make your web site stand out. To put this to the test, change the click that you added earlier to this: $("a").click(function(event){ event.preventDefault(); $(this).hide("slow"); }); Now, if you click any link, it should make itself slowly disappear. Chainability (The Magic of jQuery) jQuery uses an interesting concept to make its code short and simple. For those familiar with object-oriented programming, this concept should be rather straightforward. In a nutshell: Every method within jQuery returns the query object itself, allowing you to 'chain' upon it, for example: $("a").addClass("test").show().html("foo"); Each of those individual methods (addClass, show, and html) return the jQuery object, allowing you to continue applying methods to the current set of elements. You can take this even further, by adding or removing elements from the selection, modifying those elements and then reverting to the old selection, for example: $("a") .filter(".clickme") .click(function(){ alert("You are now leaving the site."); }) .end() .filter(".hideme") .click(function(){ $(this).hide(); return false; }) .end(); reference link http://docs.jquery.com/How_jQuery_Works



Blogger Image
My Blog Title

Product Engineering, software engineering company, Product Development, Product Migration, Product Re-engineering, Product Maintenance, Product Testing Commercial Application Development, Business Software development, commercial software for startups, Application Support and Maintenance, software testing Product Maintenance, Outsource product maintenance, product support and maintenance Product Migration, Product Re-engineering, product re-engineering services Product Research, Product Engineering, UI Prototyping Services Software Testing Services, Quality Assurance services, professional software testers, Load Testing, Functional Testing, Cross Platform, Browser Testing, Test Automation, Testing Tools, software quality analysis Functional Testing Services, software quality analysis, Software Testing Services, Application Testing Services, Functional Testing Types Automated Testing, Automated Testing Services, automation testing, test script development, Automation Test Tools, outsource automation testing Load Testing, Performance Testing Services, Load Testing Tools Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Benefits of IT Outsourcing, Offshore Software Development companies, offshore software development firms Outsource planning, IT outsourcing, IT development services, offshore IT companies, offshore software development Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering