Why do we use jQuery over JavaScript?


jQuery is a JavaScript library, so it operates on top of JavaScript. It cannot exist on its own, so you can't use one over the other. You can use just JavaScript or JavaScript and jQuery. jQuery was introduced to make development with JavaScript easier. It will reduce the development time. Use it to add animation and even handling on your website.

jQuery simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is easier to use compared to JavaScript and its other JavaScript libraries. You need to write fewer lines of code while using jQuery, in comparison with JavaScript.

Let us see the following code snippet as an example of jQuery and JavaScript to change the background color:

JavaScript

function changeColor(color) {
   document.body.style.background = color;
}
Onload=”changeColor('blue');”

jQuery

$ ('body') .css ('background', '#0000FF');

As shown above, both the code snippets are doing the same work of changing the background color. But jQuery takes less code and in this way you can work around other examples, which shows that jQuery minimizes the code and is easier to use.

Updated on: 30-Jul-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements