Wednesday 14 December 2016

jQuery for Beginners

jquery is library written in javascript to ease your javascript code. jQuery greatly simplifies JavaScript programming along with easy-to-use API that works across a multitude of browsers which saves time which you would spend on bunch of complicated codes of javascript, like ajax calls,dom manipulation,each loops,etc. The jQuery syntax is tailor-made for selecting HTML elements and performing some action on the element(s).
Basic syntax is: $(selector).action()
Examples:
$(this).hide() - hides the current element.
$("p").hide() - hides all elements.
jQuery selectors are one of the most important parts of the jQuery library. jQuery selectors allow you to select and manipulate HTML element(s). jQuery selectors are used to "find" (or select) HTML elements based on their name, id, classes, types, attributes, values of attributes and much more. All selectors in jQuery start with the dollar sign and parentheses: $().
Example:
When a user clicks on a button, all elements will be hidden:
$(document).ready(function(){
$("button").click(function(){
$("p").hide();
});
});
As we all know JQuery become much popular over a long period of time but for beginners who have started getting their hands in JQuery, there are some basic things you need to know first:-
  •  JQuery is a fast, small, and feature-rich JavaScript library.
  •  JQuery was released by John Resig in 2006 and is currently being utilized by over 31% of the most popular websites on the internet, thus it has gained popularity.
  •  The most advantageous thing about JQuery is its open source and not only that it is also dual - licensed under the MIT License and GNU general public license V2. This means any developer can create a JQuery plug-in of their own.
  •  JQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into methods that you can call with a single line of code.
  •  JQuery also simplifies a lot of the complicated things from JavaScript, like AJAX calls and DOM manipulation.
  •  Last but not the least there are bunches of JQuery plug-ins out there which you may require for any of your task.
The best feature in JQuery is that the team of developers who had developed it had a vast knowledge of cross-browser compatibility and they have fixed most parts of it and they are on with it following with the updates. JQuery runs exactly same on all major and minor browsers, including IE6.
If you are planning to use any kind of designing frameworks such as bootstrap or Zurb foundation you are going to require JQuery. Let’s compare normal javascript vs JQuery:
Normal javascript:
document.getElementById("myBtn").addEventListener("click",function()
{
alert("Hello World!");
});
Jquery:
$("#myBtn").click(function()
{
alert("Hello World!");
});
This is how JQuery reduces your effort of writing long javascript code and saves your time. You could run JQuery on any client that supports HTML & Javascript , i.e. All modern desktops, smartphones, laptops, and any future device which supports html and javascript. We develop our projects in php, php MVC frameworks like Codeigniter, Magento and Wordpress. So we use Jquery and apply to different kinds of frameworks endpoints and communicate it to the frontpoint via HTTP, so in future if we have to work on python or any other language so all we need to do is work on our server side framework. It is also better for SEO (search engine optimization) because in this everything is in text instead of flash.
So far we have seen the advantages of JQuery but as we all know everything has a weakness and so does JQuery too. Lets hav a look at it:
Limited functionality:
As we know JQuery has the best documentation and a large community of opensource developers and impressive number of libraries but it depends on how much customization you require on your web application because in some cases it’s functionality is limited so you may have to use raw javascript.
Dependency:
Dependency is a weakness which most of the people don’t almost like because in order to run JQuery Commands the JQuery javascript file is a compulsory Requirement , although the size of JQuery production version is small maybe 25-100KB.

No comments:

Post a Comment