jQuery is a JavaScript library that allows web developers to add advanced functionality to their websites. It is available from and freely available under the MIT license. In recent years, jQuery has become the most popular JavaScript library used in web development.

jQuery example

To implement jQuery, a web developer needs to reference a JavaScript file in the HTML code of a web page. Some websites host their own local copy, while others simply link to a library hosted by Google or a server. For example, a web page could load the jQuery library using the following line in the HTML section (jQuery and cookie example):

jQuery and Ajax examples

Once the library is loaded, the web page can call any function supported by the library. Common examples include changing text, processing form data, moving elements on a page, and performing animations. jQuery can also work with Ajax code and the likes of PHP and ASP to access data from a database. Because jQuery runs on the client side (not the web server), it can update information on a web page in real time without reloading the page. A common example is autocomplete, in which a search form automatically displays general data as you enter a query.

Benefits of the library

Besides free license Another main reason jQuery has gained so much popularity is its cross-browser compatibility. Since each browser renders JavaScript differently, it can be difficult for a web developer to make a website look the same across all browsers. Instead of writing custom functions for each browser, a web developer can use a single jQuery function that will work in Chrome, Safari, Firefox and Internet Explorer. Multi-browser support has caused many developers to move from standard JavaScript to jQuery as it greatly simplifies the coding process.

Description

jQuery syntax is used to simplify document navigation, selecting DOM elements, creating animations, handling events, and developing Ajax applications. jQuery also gives developers the ability to create plugins on top of the JavaScript library. It allows programmers to create abstract designs for low-level interaction and animation, advanced effects, and high-level, themed widgets. The jQuery library's modular approach allows you to create powerful, dynamic web pages and web applications.

Set of basic functions:

  • selecting DOM elements;
  • bypass and manipulation using the selection mechanism;
  • new programming style;
  • merging algorithms and DOM data structures.

The style influenced the architecture of other JavaScript frameworks such as YUI v3 and Dojo, and also inspired the creation of the standard Selectors API.

Microsoft and Nokia provide jQuery on their platforms. Microsoft includes it with Visual Studio for use within ASP.NET AJAX and ASP.NET MVC, and Nokia has integrated it into the Web Time Widget development platform.

Review

jQuery is a library of elements with a Document Object Model (DOM). The DOM is a representation of the tree structure of all elements of a web page. jQuery simplifies the syntax for finding, selecting, and manipulating these DOM elements. The library can be used to find an element in a document with a certain property (for example, all elements with an h1 tag), change one or more of its attributes (color, visibility), or respond to an event (for example, a mouse click).

Development

The library uses popular JavaScript features such as fade ins and fade outs for hiding elements, animations, and working with jQuery CSS elements. jQuery also provides a paradigm for event handling that goes beyond selecting and manipulating DOM elements. Assigning an event and defining a callback function are done in one step in one place in the code.

Design principles with using jQuery(examples):

  • Separate JavaScript and HTML - The library provides a simple syntax for adding event handlers to the DOM with using JavaScript, instead of adding HTML event attributes to call JS functions. Thus, it encourages developers to completely separate JavaScript code from HTML markup.
  • Conciseness and Clarity - Promotes conciseness and clarity with tools such as chaining and shortened function names.
  • Resolving cross-browser incompatibilities - JavaScript engines different browsers are slightly different, so JS code that works for one browser may not work for another. Like other JavaScript toolkits, jQuery handles all of these cross-browser inconsistencies and provides a consistent experience that works across browsers.
  • Extensibility - New events, elements and methods can be easily added and then reused as a plugin.
Story

jQuery was originally released in January 2006 at BarCamp NYC by John Resig and was influenced by Dean Edwards' early cssQuery library. It is currently maintained by a team of developers led by Timmy Willison (with the jQuery selector engine - Sizzle, led by Richard Gibson).

Peculiarities

The library includes the following functions:

  • selecting DOM elements using a multi-server open selector mechanism source code Sizzle;
  • highlighting a DOM manipulation project based on CSS selectors, which uses element names and attributes, such as id and class, as criteria for selecting nodes in the DOM;
  • Events;
  • effects and animations;
  • ajax;
  • deferred and promise objects to control asynchronous processing;
  • JSON parsing;
  • extensibility through plugins;
  • utilities such as feature discovery;
  • compatibility methods that are natively available in modern browsers, but need earlier versions such as inArray() and each(), multi-browser (not to be confused with cross-browser).
Usage

The jQuery library is one JavaScript file containing it all general functions DOM, events, effects and Ajax. It may be included in a web page by linking to a local copy or to one of the many copies available on public servers. The library has a content delivery network (CDN) hosted by MaxCDN.

jQuery example in PHP:

Styles

jQuery has two usage styles:

  • Through the $ function, which is a factory method for the jQuery object. These functions, often called commands, are integer because they all return jQuery objects.
  • Through $ are prefix functions. These are service functions that do not directly affect the object.
  • Accessing and manipulating multiple DOM nodes in JQuery typically begins by calling the $ function with the string This returns a jQuery object referencing all matching elements in the HTML page.

    Conflict-free mode

    jQuery includes a .noConflict() mode that releases control of the $. This is useful if jQuery is used with other libraries that also use $ as an identifier. In conflict-free mode, developers can use libraries as replacements for $ without losing functionality.

    Advanced functionality

    Callback functions to handle events on elements that have not yet been loaded can be registered within .ready() as anonymous functions. These handlers will only be called when the event fires. For example, the following code adds a handler for a mouse click on an img image element:

    $("img").on("click",function())(

    //process click event on any img element on the page

    Some functions return certain values(e.g. $("#input-user-email").Val()). In these cases the chaining doesn't work because the value doesn't reference a jQuery object.

    Creating New Elements

    In addition to access to DOM nodes through the object hierarchy, it is also possible to create new elements if the string passed as an argument to $() looks like HTML. For example, the string finds the element select HTML with ID cards and adds an option element with the value VAG and the text Volkswagen:

    $("# select carmakes")

    Append($("")

    Attr((value:VAG))

    Append (Volkswagen)).

    Utilities

    jQuery functions prefixed with $ are utility functions that affect global properties and behavior. The following example uses the each() function, which iterates through arrays:

    $.each(,function())(

    console.log(this+1);

    This jQuery post example writes 2, 3, 4 to the console.

    Ajax

    It is possible to do Ajax using jQuery's $.ajax(), an example of which is the related methods for loading and processing remote data:

    url: "/process/submit.php",

    name: John

    location: Boston

    )).done(function(msg)(

    alert("Data Saved:"+msg);

    )).fail(function(xmlHttpRequest, statusText, errorThrown)(

    alert(

    "We were unable to send your message.\N\n"

    +"XML Http Request:"+JSON.stringify(xmlHttpRequest)

    + ",\nStatus Text:"+statusText

    + ",\nError Thrown:"+errorThrown);

    In this example, the server has dataname=John and location=Boston for /process/submit.php. When this request completes, a function is called to alert the user. If the request fails, it will alert the user about the error, the status of the request, and the specific error.

    Plugins

    jQuery architecture allows developers to create plugin code for extensions various functions. There are thousands of plugins available on the internet that cover a range of features such as Ajax helpers, web services, dynamic lists, XML and XSLT tools, drag and drop, events, processing cookies and modal windows.

    There are alternative plugins for search engines, such as jquer.in, which take more specialized approaches, such as listing only plugins that meet certain criteria (such as those with a public code repository). The developer provides the Learning Center, a jQuery resource for beginners that can help users understand JavaScript and get started developing plugins.

    jQuery UI

    jQuery UI is a collection of GUI widgets that are animated visual effects and themes implemented using jQuery CSS (a JavaScript library), Cascading Style Sheets, and HTML. According to JavaScript analytics service Libscore, jQuery UI is used by over 197,000 top websites, making it the second most popular JS library. The most famous of them: Pinterest, PayPal, IMDb, The Huffington Post and Netflix.

    jQuery UI is free and open source, distributed by the Foundation under the MIT license. Was first published in September 2007.

    jQuery Mobile

    jQuery Mobile is a touch-optimized web framework (also known as a mobile framework). The development focus is on creating an infrastructure compatible with a wide range of smartphones and tablet computers necessary for the growing digital technology market. Compatible with other platforms mobile applications such as PhoneGap, Worklight and many others.

    This, one might say, is a kind of final post of what I managed to “cook up” while maintaining this blog, using the wonderful jQuery framework.

    • — two very simple universal options for creating tab switches. Example in the sidebar.
    • — when you hover over a link, a list of links to save the page in social bookmarks appears. When you click on the “Add to bookmarks” link, you switch between the list of bookmarking services and social networks. Unfortunately, not all social media the ones I added to the list exist in this moment.

      I recently abandoned this script in favor of a more beautiful solution - I created a floating panel, which you can now see to the left of the post. I like this option better, and it is more in line with modern trends. I'll probably write a post about creating such a panel.

    • — at the moment the working example is located at the top right under the search form. I'm thinking of removing this feature from the blog. I wonder if anyone actually uses it?
    • - a script that changes the font size of the page depending on the size of the browser window. For myself, I have not yet found a use for this script anywhere.
    • — a preview appears under the form for adding a comment as you type. You can attach it to any site with a form.
    • — a preview appears when you click on the corresponding button and is displayed instead of a text field. In my opinion, this is a more beautiful solution than the first option. This script can also be attached to any website.
    • . This script is for users of the Twitter web interface and amateurs Opera browser. Although, I think there is a way to attach it to other browsers.
    • — Based on the above 2nd option, I created this plugin. I really like how it turned out. To date, it has been downloaded about 8 thousand times.
    • — a plugin similar to the previous one, only for the post creation/editing page in the admin panel.
    • - this is for those who know how to connect UserJS scripts to their browser. Convenient pop-up login form.
    • — shows the visitor a welcome message next to the comment adding form if he has left a comment at least once.
    • - this is for WordPress users who have the caching function from Maxim.

      The script has a bug with UTF-8 - if you write the name in Russian letters via FireFox, then the characters from the cookie are inserted in crappy ways. A solution was suggested in the comments, but nothing worked for me.

    • — the idea was borrowed from Habrahabr. It makes sense to place it when large discussion threads are formed in the comments of the site.
    • — the interface works using jQuery, and the translation works using Google API.

      I came up with a very successful and popular solution - my widget currently consistently holds 2nd place in the list of most downloaded ones, which is good news.

    And a couple more jQuery scripts that I haven’t written about anywhere, but which are used on this blog:

    • Quoting a comment - if you select any piece of text in the comments, a panel with a link “insert a quote in the answer field” pops up near the selection; when you click on it, the selected text will be inserted into the form for adding a comment.
    • Validation of the “Name” and “E-mail” fields in the form for adding a comment. If one of these fields is filled in incorrectly, they are highlighted.

    Here is a considerable list. I think it will grow even more over time - I really love jQuery and the process of writing scripts on it.

    In general, jQuery for me is the next stage in my development as a web developer, after CSS and HTML. If I’m already quite strong in the last two technologies and there’s nowhere to move, then jQuery is, as they say, an unplowed field, and there’s room to go in this direction.

    Blogger Max1mus publishes current ways to make money on the Internet on his personal blog. useful information about blogging, SEO, SMO, and also shares personal experience about website promotion.

    10 years ago, when jQuery was just in its infancy, the browser ecosystem was very diverse and each of the products that existed then struggled with the complexity of manipulating DOM elements in its own way. The ambitious goal that the jQuery developers set for themselves was to develop a universal approach to solving these problems and create an API that would work equally well in any situation.

    As far as they were able to judge, but after 10 years of its existence, jQuery remains one of the most popular JavaScript libraries.

    JavaScript itself is now a completely mature product, well documented and supported by all modern browsers. The modern browser community is also more consolidated and, in most cases, you can be sure that if, say, a page is displayed correctly in Crome, then it will look the same in Firefox. querySelectors are also supported by almost all modern browsers.

    It would seem that the history of jQuery development is moving towards sunset - why overload pages and waste extra processor cycles if most problems can be solved standard means language? On the other hand, over such a long period for the computer industry, a huge number of solutions have been developed that can simply be taken and used, here and now.

    I think this choice should be made by the developer himself in each specific situation, focusing not on fashion and trends, but on common sense and the prospects for the development of his creation.

    In this review I have collected all the information I know free plugins jQuery that are currently under active development or have been updated at least once in the past year. Some of them I actively used and use in my practice, some I know only superficially, but they impressed me with their capabilities. Among them there are exceptionally extraordinary ones, made with great imagination. And even if you don't find a way to use them in your projects, maybe they will inspire you to create your own, even more incredible solutions.

    multiscroll.js An interesting solution to attract the visitor's attention - page scrolling is made in the form of two panels, one of which slides up and the other down, opening the next block. It also works great on all, even very outdated browsers.

    jquery.email-autocomplete.jsEmail addresses have to be entered very often and, despite the fact that this is only a dozen characters, there is often a desire to speed up this process. jquery.email-autocomplete.js has its own list of popular domains postal services on the basis of which it offers address autocompletion. The user can accept this prompt by pressing the Tab key or the right arrow key, or continue to type further manually. The plugin works well in mobile versions site. However, you will have to modify the plugin a little for it to start working with domestic email services.


    tinyDatePicker This plugin packs a lot of power into 5 kB. Calendars, planners, booking goods and services - this is not a complete list of where you can use tinyDatePicker. Fast, lightweight, scalable - it can be easily integrated into Bootstrap or any other framework.


    ReadRemaining.js Many of us are always sorely short of time. I have always envied people who know how to manage it correctly. Probably, the author of the ReadRemaining.js plugin is one of these. Who else could have thought of displaying information next to the text about how long it will take you to read it? And as you scroll through the text, recalculate this time based on the reading speed of a particular user.

    A very original plugin that I think visitors will like if you have a lot of long text material.

    TooltipsterClassic tooltip with a wide range of functions and options. The element itself can be located anywhere in relation to the parent element and contain any elements. The main thing is not to overdo it with its use, use it only where it is really necessary.

    AddelDespite the similar name, this plugin has nothing to do with the singer Adele. Its name comes from the English words ADd-DELete (add and remove) and reflects its purpose - to dynamically add or hide HTML elements, primarily form elements. The controls are flexible and intuitive.

    Chart.jsAn actively developing plugin that allows you to display Various types diagrams (8 types in total, including mixed ones). Works great on all modern browsers and has smooth and nice animation when changing data.


    jQuery Flip-Quote A very interesting plugin that does two things. Firstly, it rotates blocks of quotes present on the page at the moment when the block becomes visible (great for attracting attention). Secondly, when you click on this block, the quote in the text is highlighted, which allows you to quickly find it in the general flow of material. It turns out that quotes can be made entertaining too!

    Algolia PlacesFast search with auto-completion of postal addresses, cities, routes and everything related to locations around the world thanks to integration with the OpenStreetMap database. A very useful plugin for online stores.

    HideSeekA simple but functional live search plugin. Can search based on various criteria, perform certain actions after finding the required data, and much more.

    TimedropperThere are a huge number of convenient input solutions certain point time. However, Timedropper stands out among them due to its simplicity and easy operation. Changing the hours and minutes with this fun little tab is really convenient. It has several customization options, such as: time format (12 or 24 hour), color of the dial, test, background, and the ability to change the hours and minutes using the mouse wheel. By the way, there is a similar plugin for setting the date.

    LorySlider written in pure JavaScript. Minimalistic, but supports gesture control, setting a fixed element, displaying button controls and simultaneous display of several images, including those of different widths.

    CurrencyFormatter.js A very simple and small script that displays numerical values ​​in monetary format. Adds periods, spaces to separate digits, and a currency symbol. Supports 155 world currencies.

    Shave.jsJavascript, which will neatly trim text that does not fit into a container of a given height. It takes up only 1.5 kB and does not require third-party libraries.

    jQuery LinechartLibrary for drawing diagrams various types and quite a large amount of initial data. Written in HTML/CSS/JS, but there is also a version based on Angular.js

    FreewallIncredible beautiful jQuery plugin for creating a tiled interface in the most different styles: Windows Metro, Pinterest, regular flat or hierarchical, with draggable and dynamically added elements. Works great as mobile browsers, and on desktop, including IE8. A truly versatile tool!

    rowGrid.js A tiny plugin that arranges images or other elements in even rows of equal height, adjusting the size and spacing between them so that each row fits perfectly into the width of the window. True, all objects must be the same height.

    SlidebarsSlidebars adds a menu or menu to a website page sidebar, which appear or disappear with a sliding motion when the cursor clicks on the control button. Version 2 of this plugin has been completely rewritten and can now contain an unlimited number of different elements. It has a full-fledged API, the ability to connect your own callback functions and subscribe to events.


    pagePiling.js is very similar to the multiscroll.js plugin discussed in this review, but the page is not split into two panels, but shifted entirely. You can change the displacement direction and speed. A good choice for a one-page site that will look equally good on mobile devices and on big screens.

    AnimsitionThe main goal of Animsition is to implement a large and diverse set of different transitive effects in one plugin. These include fading and developing, rotating, reflecting, zooming, etc. (total 58 pieces).

    ZooMove I don't like the dynamic zooming of images on hover - I find this effect too annoying. But if you really want to use it, then it’s better to take ZooMove for this purpose. No other plugin will provide such smooth and smooth scaling and scrolling.

    Rippleria A lightweight plugin that creates The ripple effect(similar to ripples on the surface of water) on any DOM element: button, DIV element, image. Very easy to set up and manage.

    FlickityFast, responsive, and gesture-controlled slider. Externally - quite ordinary, but with incredibly carefully written and structured documentation. Complete and well-thought-out API.


    Unslider A very small and simple slider that has several parameters that allow you to diversify its behavior: different directions of movement (horizontal and vertical), cyclic (endless) scrolling, autoplay.

    Lightcase.js Outstanding lightbox with CSS3 animation. Works with DIVs, images, text, flash objects, video and iframe. It does not yet support jQuery 3, but the developers promise to fix this in the coming releases.


    PhotoSwipeA wonderful image gallery with control of both the keyboard on desktop browsers and gestures on mobile. It is possible to set a delay in loading photos until the page itself is completely loaded. And all this fun is only 14 kB in size.


    StripStrip is a lightbox that occupies some area of ​​the page, leaving the page itself not only partially visible, but also accessible for interaction. In addition, it can simultaneously work as a slider. In addition, along with images, it also supports video content from Youtube and Vimeo.

    Turntable.js An incredibly impressive approach to showcasing a product, especially if it's a physical object. In fact, the plugin is very simple and just shows a bunch of images. However, thanks to the ability to control the process using the mouse wheel or gestures on the screen, provided that the set represents images of one object taken from different angles of view, the viewer has a complete illusion of its rotation.

    Vide.jsPerhaps the easiest way to add a background video to a website page is to use the Vide.js plugin. It works on all modern browsers starting with IE9+. On iOS and Android, which do not always play background video, a still frame will be shown.


    TrianglifyIf you don't want to burden the page with background video, but a static image seems banal, try trianglify! These are unique geometric triangular patterns that will add some personality to your design. The plugin allows you to change color, cell size and dispersion. You can even write your own implementation of the algorithm and use it in Trianglify.

    LazeeMenuIf you have a large hierarchical menu on your website that you want to keep simple and clear, then LazeeMenu will undoubtedly be useful to you. It converts nested unordered lists into a convenient dropdown menu.

    Web-ticker A running line, similar to those that can often be seen on the TV screen in news releases - the latest events, stock quotes, weather... You never know what can be placed there! So, if you like this way of presenting information, take Web-ticker into account.

    InputmaskUser experience in action. Do you remember those times when you had to re-enter data into a form because of an error. Moreover, the error was detected only after the server responded. Forget about it! Inputmask not only controls and visually displays the correctness of the entered data, it also prevents the entry of incorrect ones. Try, for example, entering the 13th month in the date field. Masks can be very different - dates, phone numbers, e-mails and even regular expressions.

    This will install jQuery in the node_modules directory. Within node_modules/jquery/dist/ you will find an uncompressed release, a compressed release, and a map file.

    link Downloading jQuery using Bower

    The second version helps you update code to run on jQuery 3.0 or higher, once you have used Migrate 1.x and upgraded to jQuery 1.9 or higher:

    link Cross-Browser Testing with jQuery

    Be sure to test web pages that use jQuery in all the browsers you want to support. The site makes available virtual machines for testing many different versions of Internet Explorer. Older versions of other browsers can be found at oldversion.com.

    link jQuery Pre-Release Builds

    The jQuery team is constantly working to improve the code. Each commit to the Github repo generates a work-in-progress version of the code that we update on the jQuery CDN. These versions are sometimes unstable and never suitable for production sites. We recommend they be used to determine whether a bug has already been fixed when reporting bugs against released versions, or to see if new bugs have been introduced.

    link Using jQuery with a CDN link Other CDNs

    The following CDNs also host compressed and uncompressed versions of jQuery releases. Starting with jQuery 1.9 they may also host ; check the site's documentation.

    Note that there may be delays between a jQuery release and its availability there. Please be patient, they receive the files at the same time the blog post is made public. Beta and release candidates are not hosted by these CDNs.

    Surely, you have heard about the wonderful Javascript library called jQuery. What exactly is jQuery?

    How to make a web developer's life easier? Where to begin? jQuery makes writing Javascript fun and easier. With this library, many fairly complex aspects of Javascript can be easily implemented into any application.

    Today's lesson will tell you how to get started with jQuery and how to write your first script.

    What is jQuery?

    jQuery is a very lightweight Javascript library (some call it a framework) that takes the headache out of writing Javascript code. It has a lot of very powerful features, such as DOM tracking, adding beautiful effects and animations to elements, super simple Ajax techniques and methods. On the main page of the jQuery site, the most accurate description, in my opinion:

    jQuery is a fast and concise library that simplifies event handling, animation, and Ajax interaction for more fast web development. jQuery is designed to change the way JavaScript is written.

    What are the benefits of jQuery?

    Let's take a quick look at some of the advantages and properties of this framework:

    The amount of code (required for the script to run) is significantly reduced compared to JavaScript, which in turn means less time spent and more readable code. The rest of the article will look at some examples.

    Much easier to understand the code (unlike JavaScript). In our world, the sooner you finish the programming process, the more time you can devote to other goals.

    Very convenient documentation and an active community, always ready to help if necessary.

    Using Ajax becomes much easier. You only need 5 lines of code (sometimes less) to create a simple Ajax request.

    A huge number of plugins with which you can do almost anything.

    jQuery is fun :)

    How to start?

    First of all, you need to visit home page jQuery official website and download the latest version of this framework. After downloading, you need to upload this file to your hosting, and write a link to this file in the header of the document.

    Alternatively, you can use the help of the great Google and put a link to their server, where the latest versions of any frameworks are always located. The necessary link can be found.

    Is the document ready?

    To execute our first jQuery script, we need to wrap our entire script into a function. This function will be executed when the DOM is completely ready (when “the document is ready” - literal translation from English). Note that this is very similar to the popular 'onload' event, but is not the same. Let's look at an example:

    $(document).ready(function())( //Code here ));

    Above we are telling jQuery to execute any code inside the function, with the DOM completely ready. This has its advantages, despite the fact that it may not be clear to many. First of all, using this technique, we completely separate Javascript from HTML. Secondly, we do not need to wait for the page to fully load, the DOM is enough to load.

    For lazy coders, or for those who count every character, you can further shorten the code above:

    $(function())( //Code here ));

    Your first jQuery script

    We already know how to reference the library. We also understand a little about the document.ready function. Now it's time to write a simple script.

    Let's make it as simple as possible. For this example, let's make a page with text and a quote at the end. We want to show the quote only if the user clicks on the button. Take a look below at the code required for this:

    $(document).ready(function())(
    var myQuote = $("#my_quote");
    myQuote.hide();
    $(".button").click(function())(
    myQuote.show(500);
    });
    });

    Let's take a closer look at the entire code.

    As mentioned above, we put all the code to be executed inside the $document.ready() function.

    We assign the id of our quote (my_quote) to the myQuote variable. Now we have access to the quote with id my_quote.

    That's all. When you press the button for 0.5 seconds, a quote will be shown. Very easy, isn't it?

    To be continued....

    Thank you for your attention! All the best!