[javascript] What is the difference between JavaScript and jQuery?

What is the main difference between JavaScript and jQuery. I know the minor difference like jQuery is high performance more reliable.

This question is related to javascript jquery

The answer is


jQuery is a multi-browser (cf. cross-browser) JavaScript library designed to simplify the client-side scripting of HTML. see http://en.wikipedia.org/wiki/JQuery


Javascript is base of jQuery.

jQuery is a wrapper of JavaScript, with much pre-written functionality and DOM traversing.


jQuery is a JavaScript library, that can be used for communicating (selecting html elements, attaching event listeners, animations etc.) with the DOM, creating and consuming AJAX requests, as well as other things in a more easier way rather than using plain JavaScript. jQuery is written in JavaScript. It should be mentioned that browsers parse only HTML, CSS and JavaScript files. Hence, all JavaScript libraries/frameworks (jQuery, Knockout, Angular) are written in JavaScript or in languages like TypeScript that transconpiles to JavaScript (e.g. Angular 2). They provide you the opportunity to write less lines of codes or to create interfaces following patterns like MVC (e.g. Angular), MVVM (e.g. Knockout) as well as other patterns, but under the hood, they are all result in a JavaScript file.

An example in order to understand why using jQuery you write less do more is the following.

Let we have the following input element

<input id="button1" type="button" value="clickMe"/> 

Also, let that we want when someone clicks on the button to be notified through an alert box showing to the user a 'Hello' message.

If we had to do this using plain JavaScript, we would have written the following:

document.getElementById("button1")
        .addEventListener('click', function(){ 
            alert("Hello");
        });

On the other hand, if we were using jQuery, we would had achieved the same result by just writing this:

$('#button1').click(function(){ 
    alert("Hello"); 
});

Using jQuery makes things more clear than using plain JavaScript for the same purpose. (write less do more is jQuery's moto)

Furthermore, jQuery handles pretty well the theme of browser compatibility, you can use their API pretty easily without wondering too much as if you should do in case of using plain JavaScript.

Below I have added snippets for the code above:

_x000D_
_x000D_
document.getElementById("button1")_x000D_
        .addEventListener('click', function(){ _x000D_
            alert("Hello");_x000D_
        });
_x000D_
<input id="button1" type="button" value="clickMe"/>
_x000D_
_x000D_
_x000D_

_x000D_
_x000D_
$('#button1').click(function(){ alert("Hello"); });
_x000D_
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>_x000D_
<input id="button1" type="button" value="clickMe"/>
_x000D_
_x000D_
_x000D_


Javascript is a programming language whereas jQuery is a library to help make writing in javascript easier. It's particularly useful for simply traversing the DOM in an HTML page.


jQuery was written using JavaScript, and is a library to be used by JavaScript. You cannot learn jQuery without learning JavaScript.

Likely, you'll want to learn and use both of them. go through following breif diffrence http://www.slideshare.net/umarali1981/difference-between-java-script-and-jquery