What is the difference between JavaScript and jQuery [closed] - 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
Possible Duplicate:
What is the difference between jQuery and JavaScript?
Would please tell me the difference between Javascript and Jquery? I know about PHP and MySQL. Now,I want to learn JavaScript.

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.

JQuery is built on top of JavaScript.
JavaScript is pretty powerful, but can be difficult to program. jQuery is sort of a wrapper around JavaScript that makes it easier to program.
For example, instead of JavaScript's
document.getElementById('myDiv').style.backgroundColor="#FFF"
in jQuery you simply do
$('#myDiv').css('background-color','#FFF');
jQuery also simplifies stuff like XMLHttpRequests and such like. jQuery allows one to focus on the problem and not worry about what goes on in the underlying JavaScript too much.
That's my half-arsed attempt at explaining things. I'm sure someone can do better!

Jquery is Javascript's function. It's framework (library), which helps you (from Jquery's moto:) "Write less, do more"

the difference is javascript is a language and jquery is a library created by using javascript...
here is an excellent SO link with learning javascript resources https://stackoverflow.com/questions/11246/best-resources-to-learn-javascript

jQuery is a javascript framework that extends a lot of the basic functionality of javascript (better DOM traversal, animation stuff, cross-browser compatibility, etc).
The Wikipedia page gives a good explanation.

Related

Is it a bad practice to use jQuery in Angular? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
My question is the following. Should I avoid using any kind of jQuery code in Angular application as it seems legit to have only one thing interacting with DOM.
Another question is if anyone came across problems where he couldn't find any other solution but writing a quick hack with jQuery.
Thank YOU!
Yes it's a bad practice, but sometimes it will save you much time, especially when you are looking for a plugin,
Do it when necessary only, and keep a note to switch it back when other solutions are available.
The first thing you should do is to read this thread on SO "Thinking in AngularJS" if I have a jQuery background?. This will give you some perspective.
When it comes to Angular, it the model that drives the view and most of the times direct DOM manipulation is not required.
For example if you are using DOM manipulation to show\hide element, add remove class or set style, then better to use ng-show\ng-class\ng-style directive.
But there are cases when DOM manipulation is required and that is the time you write directives and either use jqLite or jQuery to manipulate DOM.
My suggestion would be to avoid jQuery unless you have to incorporate a jquery plugin that is dependent on jQuery.
While developing always look if the inbuilt directives that can serve your purpose. If not can jqLite be used to achieve what is desired. Your final resort should be jQuery.
Well it's just two large resources, which makes your app "heavy". Otherwise it's only a preference thing. Personally I don't use jQuery with any of the reactive frameworks (Vue, React nor Angular).
Remember that anything jQuery can do, you can do with vanilla JS.

Embed Javascript in HTML Coding Best Practice [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 4 years ago.
Improve this question
I am writing my first html application. I have both JavaScript and jQuery embedded at the bottom of the html file.
Is it a good practice to mix JavaScript and jQuery together?
Currently, I am importing jQuery 3.3.1; what if next version comes out? How can I make the imported jQuery dynamic?
Answering your questions one by one.
First of all, you are keeping your scripts at the bottom of the page. And that is really a good practice to keep all the scripts at the bottom of the page so that it will not block rendering of the page.
Second, mixing JavaScript & jQuery code is completely a personal choice. But still, I would recommend going with either JavaScript or jQuery to maintain code consistency & it's understandability. It will be easier for other developers to understand code that is written in a consistent way. Though, there might be some points where you would like to prefer JavaScript to achieve performance & you should do that but such cases will be very few.
Best Practice: Write all your scripting code in separate file & take reference of that file in your HTML page.
Don't worry about the jQuery version updates. Current jQuery version is very very much stable, so even if the newer version comes up - you would not need to switch to that version until or unless you are blocked for some feature that is only available in the latest version.
This will be your Jquery which is in your system
<script src="jquery-3.3.1.min.js"></script>
and if you thinking according updates then you should go with CDN links
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
1) JQuery is a JavaScript framework. You can write the same exact thing in plain JavaScript that you can in JQuery. The difference is that JQuery will often be shorter and perhaps easier to read. So in short they are meant to be mixed together.
2) Also, if a new version of JQuery comes out nothing will happen to your project. Jquery is just a bunch of plain Javascript that makes things easier for you. It won't stop working because a newer version is available.
Jquery is Javascript I don't think it is bad practice to mix them!

Should I rewrite my entire JavaScript code into jQuery? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I'm currently developing a web application and I was forced to use jQuery for some animations and other specific purposes, but still most of my code is written in JavaScript.
Should I rewrite these JavaScript modules if after all jQuery is being loaded every time? I know that in some cases it is better to use JavaScript instead of jQuery because it is faster and some other advantages but I'm already using jQuery throughout the page and I'm wondering should I use it everywhere instead of loading the whole library for few chunks of code.
Will there be any significant difference in the performance if the library is already loaded?
There won't be any difference, the Javascript speed is better. The performances wihout libraries still better. So keep your modules
Its up to you.
If you don't like to use any JS library, then you have code a lot.
The current jQuery v1.12.2(supports IE 6,7,8) size is 97kb. You use CDN version to reduce the loading time of it.
Will it affect the performance?? Yes, a bit it will do.
You didn't mention whether you are making any XMLHttpRequest;
if so, its better to use jQuery for better cross browser compatibility.

Best way to use javascript in anchor tag [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
There are many ways to use JavaScript. When I use JavaScript with an anchor, I write code like this and I think this way is right.
Method One
But my co-worker uses JS like this.
Method Two
Is there a coding standard or are both methods correct?
DISCLAIMER: Inline JavaScript is, generally speaking, a bad idea, and 99% of the time you're much better off separating concerns, and using a library, such as jQuery, or whatever similar toolset that your framework of choice recommends.
Nonetheless, to answer your question, if you must use inline JavaScript, I recommend that you omit the "JavaScript:" keyword. It specifies a "pseudo-protocol," and is not necessary for modern browsers to interpret the code. It is a relic from the last decade, and there is a bug with some versions of IE:
"There is one (somewhat obscure) bug with the javascript protocol - in
Internet Explorer*, it will think you are leaving the page when you
click the link. If you are using window.onbeforeunload, then your
navigate-away message will appear at this time. For this reason alone,
we've stopped using the javascript protocol completely so we don't
have this bug show up because we forgot to check for it when we add a
navigate-away message to some page."
When do I need to specify the JavaScript protocol?
https://bytes.com/topic/javascript/answers/504856-javascript-pseudo-protocol-event-handlers
Both the ways are ok but in first way you should use a external JS file. Otherwise it is ok.
For small tasks and events second ways is good.

How to get started with jQuery Mobile? (Programmers background) [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have a background in C++/C# and Java (Android). Now, I want to pick up what seems to me the best solution for mobile web applications: jQuery Mobile.
I know some of the very basics of HTML/DOM/CSS, but not in a structured/thorough manner.
Javascript-wise, it seems to be a rather different programming approach than I'm used to.
Where do you recommend I start? Javascript (and possibly Ajax) or jQuery or could I afford by immediately starting with jQuery mobile?
Plus, could you recommend me some good learning/example sources as well?
Thank you in advance.
-Thomas
jQuery mobile is a plugin written using jQuery in order to Enhance html5 elements appearance and behaviour to match iPhone design pattern for application behaviour (Progressive enhancement).
Whilst it is fairly easy to get started filling the templates jQMobile provides as a C# developer you need to understand that working with JavaScript and jQuery has some significant differences.
jQuery was a community necessity and is basically nothing but an abstraction layer on top of JavaScript to rectify the difficulties programmers were facing which mainly had to do with the difference of JavaScript implementation in different browsers and also the weakness in the DOM which is an API which allows JavaScript to access elements inside the document.
What jQ basically does is it takes care of those differences for you and exposes methods to you that are pretty much guaranteed to deliver the same results across supported browsers.
This will greatly help you get started by still wont allow you to learn the fundamental differences between the world you are coming from and the world you are getting into.
JS does not have classes only functions. However functions can have methods and be instantiated. The inheritance in js is Prototypal Inheritance.
new f()
produces a new object that inherits from
f.prototype
more info here
To learn the basics and understand more about this language before you use it! please watch this also

Categories