access_time
hourglass_empty
person_outline

What is jQuery

jQuery is a popular JavaScript library. It was created by John Resig in 2006 with a purpose to make it easier for developers to use JavaScript on websites. It’s not a separate programing language and works in conjunction with JavaScript. With jQuery, you’re going to do a lot more with a lot less – let us explain.

Writing code can get tiresome, especially when there’s a lot of strings included. jQuery compresses multiple lines of code into a single function, so you don’t need to re-write whole blocks of code to achieve a single task.

jQuery Examples

You can create sliding effects with just a few lines of code.

You can use the SlideDown(), SlideUp() and SlideToogle() commands.

$("#flip").click(function(){
   $("#panel").slideDown();
});

With jQuery, you can also hide HTML elements with the Hide() and Show() commands like so.

$("#hide").click(function(){
   $("p").hide();
});

$("#show").click(function(){
   $("p").show();
});

And here’s an example of animation:

$("button").click(function(){
   $("div").animate({
       left: '250px',
       height: '+=150px',
       width: '+=150px'
   });
});

Here’s a code snippet on how to do CSS manipulation:

$("button").click(function(){
   $("h1, h2, p").toggleClass("blue");
});

Important jQuery Features

A feature of why jQuery became so successful and popular is probably the cross-platform capabilities. It automatically fixes errors and runs the same way on most commonly used browsers like Chrome, Firefox, Safari, MS Edge, IE, Android, and iOS.

jQuery also makes Ajax much easier. Ajax works asynchronously from the rest of the code. What this means is that the code written with Ajax can communicate with the server and update its contents without needing to reload the page.

This comes with problems, however. Different browsers execute the Ajax API differently. Thus the code must adhere to all browsers. Manually, this is tough and time-consuming work. Fortunately, jQuery does all the menial labor and adapts the code to all web browsers.

Then there’s DOM (Document Object Model) manipulation, which has several methods on how to go about it. But to put it simply, it lets you insert and/or remove DOM elements in an HTML page, as well wrapping up lines easier.

Creating animation is also simplified with jQuery. Like in the code snippet above about animation, it’s all covered with a few lines of code, all you need to do is insert the variables.

HTML document traversal, as well as doing effects and event handling are also made better with jQuery.

You may also want to get to know Hostinger better. We have plans for everyone with more than 800 domain name extensions. Feel free to choose!

For the best start, the best offers

jQuery Advantages

The benefits of using jQuery are substantial. The slogan “Write less, do more” fits jQuery perfectly. Once you learn how to use jQuery (which is rather easy), you will be able to do all sorts of complex actions with ease.

Since it’s one of the most popular JavaScript library available, there are tons of resources online on how to learn jQuery. Although having a basic understanding of JavaScript, HTML and CSS might be necessary.

All in all, if you’re using JavaScript, it’s almost mandatory to jQuery because it has many positives, while the only downside is learning how to use it.

The Author

Author

Domantas G. / @domantas

Domantas leads the content and SEO teams forward with fresh ideas and out of the box approaches. Armed with extensive SEO and marketing knowledge, he aims to spread the word of Hostinger to every corner of the world. During his free time, Domantas likes to hone his web development skills and travel to exotic places.

Related tutorials

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Become a part of Hostinger now!

More in Glossary
What is WordPress RSS Feed and How to Use It

Close