What is the difference between the two javascript codes? [duplicate] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
What is the main difference between JavaScript and jQuery. I know the minor difference like jQuery is high performance more reliable.

jQuery is a JavaScript library.
Read
wiki-jQuery, github, jQuery vs. javascript?
Source
What is JQuery?
Before JQuery, developers would create their own small frameworks
(the group of code) this would allow all the developers to work around all
the bugs and give them more time to work on features, so the
JavaScript frameworks were born. Then came the collaboration stage,
groups of developers instead of writing their own code would give it
away for free and creating JavaScript code sets that everyone could
use. That is what JQuery is, a library of JavaScript code. The best
way to explain JQuery and its mission is well stated on the front page
of the JQuery website which says:
JQuery is a fast and concise JavaScript Library that simplifies HTML
document traversing, event handling, animating, and Ajax interactions
for rapid web development.
As you can see all JQuery is JavaScript. There is more than one
type of JavaScript set of code sets like MooTools it is just that
JQuery is the most popular.
JavaScript vs JQuery
Which is the best JavaScript or JQuery is a contentious discussion,
really the answer is neither is best. They both have their roles I
have worked on online applications where JQuery was not the right tool
and what the application needed was straight JavaScript development.
But for most websites JQuery is all that is needed. What a web
developer needs to do is make an informed decision on what tools are
best for their client. Someone first coming into web development does
need some exposure to both technologies just using JQuery all the time
does not teach the nuances of JavaScript and how it affects the DOM.
Using JavaScript all the time slows projects down and because of the
JQuery library has ironed most of the issues that JavaScript will
have between each web browser it makes the deployment safe as it is
sure to work across all platforms.
JavaScript is a language. jQuery is a library built with JavaScript to help JavaScript programmers who are doing common web tasks.
See here.

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 code 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:
document.getElementById("button1")
.addEventListener('click', function(){
alert("Hello");
});
<input id="button1" type="button" value="clickMe"/>
$('#button1').click(function(){ alert("Hello"); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="button1" type="button" value="clickMe"/>

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.

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

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

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

Related

Is jquery a **normal** library to javascript the same way Math is a library to c++, python or even js?

I'm new to web development, I'm discovering javascript and all its capabilities. I'm currently learning jQuery and it made me wonder: "what really is a library ?".
From some so/internet search I understand that jQuery is a library, although some people also consider it a framework as it help/force you to change the way you code js.
For me, a library is a set of functions and classes to help the programmers on a particular point.
As I understand it jQuery doesn't seem to only add function or classes contrary to other javascript libraries such as math, for example or even other jQuery plugins like datatables etc...
To me, jQuery at its base just looks like another way of presenting js code.
So to summarise my questions are:
Is jQuery a "normal" library like Math for c++, python or even js?
How does the js engine understand jQuery? (some sort of compilation ?)
Can every js engine understand jQuery as long as they have the jQuery.js file, or is there something already embedded inside the engine for jQuery.
I also took a look at this very interesting so post on Is a jQuery compiler possible?, but it just blurred me the line between library and jQuery even more.
Any hint or link to how js/jquery combine would be helpful!
Is jQuery a "normal" library like Math for c++, python or even js?
Yes. It's just a collection of functions, etc.
How does the js engine understand jQuery? (some sort of compilation ?)
jQuery is just code written in JavaScript using the standard features of the browser (the DOM, etc.). (Well, and some non-standard ones it feature-tests for to get around browser idiosyncracies.)
Can every js engine understand jQuery as long as they have the jQuery.js file, or is there something already embedded inside the engine for jQuery.
jQuery is designed for the browser environment, so it won't work correctly in a non-browser environment without additional dependencies (a DOM library, etc.).
For the avoidance of doubt: There's nothing you can do with jQuery that you can't do without jQuery, using JavaScript's standard library, the DOM API, and other browser APIs directly. All jQuery does is provide an alternate API for doing DOM manipulation, provide some utility functions, and define a standard way to add features to extend jQuery with more functionality (e.g., "jQuery plugins").
And for completeness:
jQuery is not a language, although it's a common misconception that it is. You don't do something "in jQuery" or "in JavaScript." The correct contrast is "with jQuery" or "with the DOM" (or "without jQuery").
There are other libraries which also fill the same sort of "make the DOM easier" niche, although jQuery is by far the most successful of them.
There are entirely different approaches to handling browser-based interfaces, provided by a spectrum of projects from libraries (like KnockoutJS and many others) through light(ish) frameworks (like React and others) to full-on frameworks (like AngularJS and many others).
Its pretty simple how you understand a library and a framework when it comes to jquery its a library because it dose'nt add any additional jquery approch whatever you see in jquery is present in javascript what jquery does is shorthand your code and help you chain functions which was not that much possible in javascript and when it comes to plugin they all are also part of javascript functions

Do I need to learn Javascript before learning JQuery? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Is it a good idea to learn JavaScript before learning jQuery?
I want to learn html5 in order to write some games. I realized people include some JQuery code inside the game. So I head over and check JQuery and found that JQuery have some relationship with Javascript.
Should I learn Javascript before learning JQuery?
from http://jquery.com/
jQuery is a new kind of JavaScript Library.
jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.
So in order to use jQuery you should know JavaScript as well.
jQuery is a library for the Javascript language. Yes, you have to learn it in order to use jQuery.
JQuery is a JavaScript library, so you should definitely lear JS before JQuery. It's like trying to learn Boost without C++.
JQuery is a Javascript libary. JQuery is built on Javascript. My Javascript skills aren't high but I also use JQuery. If you learn JQuery you will learn at the same time Javascript.
jQuery is a Javascript library in itself, so I do recommend that you study up on Javascript before jumping into jQuery. Although what jQuery is able to achieve in one line of code is far from what Javascript can achieve in even 10 lines of code, it's important to learn that foundation of something before you learn the actual structure built upon it.
Yes, jQuery is just a framework/library of javascript. You should learn javascript before leaning jQuery. When you master javascript, jQuery won't cost you one day to learn.

Javascript or jquery?

I'd like to ask a simple question,
Should I use javascript or jquery?
For all I know, jquery is difficult for me to learn (the ajax part at least) and I already know javascript and how to do almost everything in javascript. In some functions I have to say that in my website I used jquery mostly because of the fancy animations but only for that. That is as far as I can go with jquery. So will jquery offer me more in performance or not? Should I learn jquery to create the ajax functions or just stick with javascript?
Also I know it wouldn't be ideal but do you believe that using both jquery and javascript (of course for different functions) will be buggy??
Thanks in advance.
EDIT: Of course I know that jQuery is a Javascript framework I'm asking if it will offer something more in performance thanks.
jQuery is Javascript.
It's just a set of Javascript functions that many people find very convenient.
jQuery.ajax in particular is much easier to use than the native XMLHTTPRequest.
There is nothing wrong with calling functions that aren't defined by jQuery.
jQuery is JavaScript. It's only a framework. So you are totally safe to use both.
Answering your updated question on how jQuery frameworks offer you more than dealing with plain JavaScript:
Write less code and do more
Cross-browser compatibility out-of-the box
A lot of really good plugins available
You should not worry about performance. jQuery gives you so much more.
jQuery is a JavaScript library, so in order to use jQuery you have to be using JavaScript.
That being said, you're free to use both. Use plain JavaScript where you want, use the jQuery library for code which is more clearly expressed in jQuery.
jQuery IS Javascript actually.
But for question, just use both, because jQuery is faster for some stuff, but it is limited. It is only Javascript library.
jQuery is javascript.
That said, if you already are using jQuery in your website, I'd recommend making use of its ajax support. It really is much nicer than attempting to write your own cross-browser implementation.
A question for you - you say you know javascript very well, so have you created a javascript plug-in? ie. a set of reusable functions that you use throughout your site?
jQuery is just this - nothing more. It is a wrapper around javascript that saves a lot of time and code in certain situations.
jQuery does not offer anything over Javascript in terms of performance. It's purpose is to make development easier, better and more productive.
You can do the same functions that jQuery does with Javascript, because jQuery is made with Javascript code.
jQuery tries to simplify a lot the visual and selection tasks that are more tedious with JS.
Use jQuery and, when you need to be more specific, add JS.
As others have noted jquery is javascript..
absolutely jquery, in my opinion, animation is not most amazing part. With jquery you can handle the cross-browser javascript code very easily, and i think the ajax part is so much easier and flexible than the pure javascript xmlhttprequest.
Yes, I would definitely go for jQuery. At start it seems to be a bit difficult, but you'll soon find out that jQuery is way easier to use and better in performance.
After all Javascript takes like 20 lines to make an Ajax call. jQuery would just do (for example):
$.ajax({
type: "POST",
url: "yourscript.php",
data: ({ id : retrieved_id,
firstname : firstname }),
success: function(data) {
$('#txt_id').html(data);
}
});
jQuery will ease up a lot of things for you. I used to be familiar with Javascript too and I was a bit hesitant to start using jQuery, but now I cannot live without it anymore!
Keep in mind though that jQuery IS just like a Javascript library. So you will still be using Javascript.

What is the difference between AJAX with JavaScript and jQuery? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
What is the difference between AJAX with jQuery and AJAX with JavaScript?
Actually only one of them is a programming language.
Javascript is a programming language which is used mainly in webpages for making websites interactive. In this context, when a webpage is parsed by the browser, it creates an in-memory representation of the page. It is a tree structure, which contains all elements on the page. So there is a root element, which contains the head and the body elements, which contain other elements, which contain other elements. So it looks like a tree basically. Now with javascript you can manipulate elements in the page using this tree. You can pick elements by their id (getElementsById), or their tag name (getElementsByTagName), or by simply going through the tree (parentNode, firstChild, lastChild, nextSibling, previousSibling, etc.). Once you have element(s) to work with you can modify them by changing their look, content or position on the page. This interface is also known as the DOM (Document Object Model). So you can do everything with Javascript that another programming language can do, and by using it embedded into wepages you also get an in-memory Object of the current webpage by which you can make changes to the page interactively.
In recent years JavaScript has also become a popular server-side language running in an environment called Node.js. This opened up a way for you to share common parts of your code between the browser and the server.
AJAX is a technique of communication between the browser and the server within a page. Chat is a good example. You can write a message, send a message and recive other messages without leaving the page. You can manage this network interaction with Javascript on the client side, using an XMLHTTP Object provided by the browser.
jQuery is a library which aims to simplify client side web development in general (the other two above). It creates a layer of abstracion so you can reuse common languages like CSS and HTML in Javascript. It also includes functions which can be used to communicate with servers very easily (AJAX). It is written in Javascript, and will not do everything for you, only makes common tasks easier. It also hides some of the misconceptions and bugs of browsers.
To sum up:
Javascript is a programming language (objects, array, numbers, strings, calculations)
AJAX and jQuery uses Javascript
jQuery is for simplifing common tasks with AJAX and page manipulation (style, animation, etc.)
Finally, an example just to see some syntax:
// page manipulation in javascript
var el = document.getElementById("box");
el.style.backgroundColor = "#000";
var new_el = document.createElement("div");
el.innerHTML = "<p>some content</p>";
el.appendChild(new_el);
// and how you would do it in jQuery
$("#box")
.css({ "background-color": "#000" })
.append("<div><p>some content</p></div>");
Javascript, for the purposes of this question, is a client-side (in the browser) scripting language.
jQuery is a library/framework built with Javascript. It is very popular because it (nearly universally) abstracts away cross-browser compatibility issues and it emphasises unobtrusive and callback-driven Javascript programming.
AJAX (Asynchronous Javascript XML) is a method to dynamically update parts of the UI without having to reload the page - to make the experience more similar to a desktop application.
EDIT:
It sounds like you're new to this. I would seriously recommend you check out http://www.w3schools.com/js/default.asp to get started. It's what I used to learn javascript and it's done incredibly well.
Of the three only javascript is a programming language. jQuery is a framework that is based on javascript and that simplifies some tedious tasks like manipulating the DOM, adding some effects and animations and most importantly doing it in a cross browser fashion. One of the tasks that is simplified by jQuery is AJAX which is a concept allowing a browser to send an asynchronous request to a web server allowing for richer web applications.
AJAX is technology.
Jquery is library.
Javascript is language.
AJAX is a method to do an XMLHttpRequest from a web page to the server and send/retrieve data to be used on the web page. It stands for Asynchronous Javascript And XML. It uses javascript to construct an XMLHttpRequest(varies between browsers).
jQuery is a javascript framework that can be used to manipulate the DOM (search and interact with the DOM). jQuery implements a high-level interface to do AJAX requests abstractly thereby giving multi-browser support in making the request.
So, Ajax is a technology paradigm, whereas jquery is a library so can't compare them.
AJAX is a way to talk to the server in the background.
JavaScript is a language that the browser understands.
jQuery is a JavaScript framework that makes life easier for people who want to program for the browser.
JS is a client-side programming language.
jQuery is a framework, but isn't the only one. Another JS frameworks are AngularJS, Mootools, NodeJS, BackboneJS, etcetera. With anyone of this frameworks you will do any action that pure JS can't do, or any "complex" (I don't find the correct word) action. As Void said, adapting his answer to my answer about frameworks: "makes life easier for people who want to program for the browser."
With AJAX you can communicate your Web page to the server. AJAX depends on JS to work.
Javascript is a scripting language, Not a programing language. Jquery and ajax are simplified version of javascript which helps manupulate queries of certain part of website without having to change the entire user interface of the website.

Is it necessary to learn JavaScript before learning jQuery? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Is it a good idea to learn JavaScript before learning jQuery?
I am about to start learning JavaScript. However one friend suggested me to go in for jQuery instead since he says future is jQuery. I heard that jQuery is created from JavaScript.
In short, give me one simple reason why developers like me should invest in JavaScript. What is its future?
Part of being a good programmer is having an interest in understanding how things work. You can't understand how JQuery works without knowing JavaScript.
A good programmer has a diversity of skills. Knowing both the JQuery way to do things and the JavaScript-only way makes you more versatile.
Most employers who are looking for someone who knows JQuery are probably also looking for someone who knows ordinary JavaScript.
You can never achieve true expertise in JQuery without understanding JavaScript.
Sometimes even a fairly lightweight framework is more than you need.
If you don't ever learn to do things the hard way, you won't appreciate what's so great about doing it the easy way.
Moreover, if you start by learning to do things the easier way, you'll have that much harder a time motivating yourself to learn to do it the hard way.
Learning the language first without the fancy frameworks builds character.
Who knows, maybe you'll want to make your own framework someday. Or even work on a new version of JQuery. To do that, you'll need to know the language.
jQuery is JavaScript and yes, it makes things a lot easier for you and you can use it without much JavaScript knowledge, and yes, it will probably become even more popular in the future.
BUT: Wherever is jQuery, there will be JavaScript. jQuery is "just" a tool. You still need "plain" JavaScript to solve some problems, e.g. string manipulation.
Imho: You cannot master jQuery if you don't master JavaScript.
And there will be situations where jQuery might be not the best solution, e.g. when you really need high performance.
For me, this is similar to other questions I read here on SO about web frameworks and programming languages, like: Do I have to learn/know PHP if I want to use [Zend | symfony | CodeIgniter].
Seriously: If you don't understand the basics, you cannot use a tool efficiently.
JQuery is a library, written in Javascript, the language. It is almost always the case that learning the library without learning the language is impractical if not impossible, irrespective of the library and the language in question.
jQuery will come and go.
You are a web developer, right? Javascript is huge. Think how much time people spend using a web browser. The entire time they are interfacing directly with html dom, css, and javascript. Or, less and less, flash and "actionscript" (which is basically javascript).
Learn javascript, learn css, learn the dom. Refer to ecma-262 versions 3 and 5 and publications by w3c and whatwg. Read mozdev, cross-check msdn.
After that, take a look at jQuery if you want. You will probably find that you don't need it for 99% of the stuff people use it for.
Every browser has its own implementation of Javascript ( the language ) and the DOM ( library for manipulating elements on the page ). Because of the inconsistency of each browsers Javascript + DOM with another, jQuery ( created with Javascript ) was created as a wrapper that internally deals with these inconsistencies so you can use the easy API.
Underneath the hood, most of your problems are already solved for you so you don't have to think about issues like:
invoking functionality for the DOM ready event
a consistent way of attaching event handlers for click, mouseover and other events, attaching multiple functions to the same action
returning the proper values for elements as well as viewport ( window ).
Because jQuery is a Javascript library you won't master it without mastering Javascript. See my previous answer for recommendations for learning Javascript.
You do not need to know JavaScript in order to use jQuery.
This depends what you want of course.
If you want to put together web pages and don't consider yourself the 'programming type' or you simply don't like JavaScript, then don't bother, spend your time where it will matter most.
Your also asking this question on a site where majority of users are developers so your going to get a lot of people who say you should learn JavaScript, I say learn it if it interests you.
There are pleanty of jQuery solutions out there and support so that you don't need JavaScript.
jQuery IS JavaScript. When you are writing jQuery, you are writing in javaScript. All a library like jQuery consists of is a premade collection of functions you can use in your JavaScript programs.
So, you have to know JavaScript syntax and the core language in order to use jQuery at all. A good book for that is Douglas Crockfords the Good Parts.
What you do not need to know as much about is the DOM API, since that is mainly what jQuery smooths over for you. It helps a lot to understand the concepts of the DOM, though. You still need to know what an element is, and what attributes are.
You also need to know about CSS in order to use jQuery effectively. The key concepts here are classes, IDs, positioning, visiblity and display, among others.
Yes you CAN use jQuery without knowing JavaScript. In fact, I knew very little about JavaScript originally but by using jQuery it sparked my interest to learn it and so I did. Years later I can say I am very proficient with both.
As you progress in your programmer expertise you would find that you go from library writer to library user. This is quite natural and OK. When you are starting off, all you have is the basics. You write your code in terms of those basics and over time find that you need to bunch common code in a library for easier reuse.
Sometime later you find that someone has already done just that and created a library that's even better than yours. You then switch from being library writer to library user. jQuery is one such library and you really need to know JavaScript to be able to draw a line in your head as to where jQuery is and where JavaScript is.
My advice, in light of the above, would be to learn the underlying technology before getting started with the library (which is what jQuery is). However in this case I would make an exception - skip DOM manipulation. DOM is a stupid abstraction and will have you tear your hair out in no time flat. jQuery wraps it up quite nicely, might as well get stuck into that after you understand JavaScript basics.
you can read this
edit
However one friend suggested me to go
in for jQuery instead since he says
future is jQuery.
If you go for jQuery, of course you are still learning Javascript...
You can not understand jQuery if you can not understand how Javascript works.
Some programmers learning jQuery wihtout the knowledge of javascript thought that they are learning a new programming scripting language. But they did not know that jQuery is not. They are just using jQuery as a tool. They are still coding Javascript...
If you want your Javascript codes to be cross-browser,
with less hassle, go for jQuery... but still you need the basic (or at least) knowledge of Javascript.

Categories