How can we differentiate jquery and javascript.?
Where we can use jquery not javascript and vice-versa.?
4 Answers
jQuery is just a javascript library. So jQuery is javascript.
3 Comments
jQuery is a JavaScript library, thus it is JavaScript - just think of jQuery as a means of writing less code to perform certain JavaScript functions and actions.
Have you had a look at the jQuery file you download and add to your project or application? What you find inside is... lots of JavaScript!
Are you asking when would you use jQuery instead of JavaScript and vise-versa? If so you will find a lot of articles out there on the web or even here on stackoverflow:
1 Comment
Javascript is a programming language which is THE dominant language on the web - every browser supports it natively.
jQUery is a library written in Javascript. So basically Jquery IS Javascript but Javascript is NOT jQuery.
Jquery is meant to make programming tasks easier which would otherwise need quite some effort when writing it with native javascipt. Also it is an additional layer which evens out some inconsistencies and differences between the several browsers (especially Internet Explorer...)
While javascript is natively available in every browser, you have to include the jQuery-script in order to use it's functions.
<head>
<script type="text/javascript" src="/path/to/jquery.js"></script>
</head>
One example to illustrate the usefulness of jQuery is making an AJAX Call. Creating the AJAX-Request Object in Javascript would look like this:
if (window.XMLHttpRequest) {
request = new XMLHttpRequest(); // Mozilla, Safari, Opera
} else if (window.ActiveXObject) {
try {
request = new ActiveXObject('Msxml2.XMLHTTP'); // IE 5
} catch (e) {
try {
request = new ActiveXObject('Microsoft.XMLHTTP'); // IE 6
} catch (e) {}
}
The jQuery-Code would look something like this:
$.ajax(/*...some options here...*/);
Jquery is providing some easy functions to keep the annoying work away from the programmer.
Comments
Well for starters you nee to include the JQuery file in your web page for you to be able to use it. Other than that, see the other comments (JQuery is a wrapper for javascript)
It's meant to ease certain aspects of coding javascript Sample taken from the JQuery site
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
// we will add our javascript code here
</script>
</head>
<body>
<!-- we will add our HTML content here -->
</body>
</html>