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!
Related
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.
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.
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
when i download a free theme or a demo tutorial in the web. I just noticed that now a days i always see those modernizr, normalise, and boilerplate thingy.
I have researched them but still i cant understand what they do? Maybe you guys can explain more or maybe use an analogy to explain it better.
It's like "Explaining New Web Development thingy for Dummies" Really appreciate it.
Due to the differences in browsers and platforms, these libraries try to make is so that you don't have to use browser-specific code to take advantage of all the new HTML5 features.
Another way of saying it is, since all browsers "interpret" the HTML5 standard differently, these libraries help to smooth out the differences between interpretations.
Modernizr: http://modernizr.com/
Taking advantage of cool new web technologies is great fun, until you have to support browsers that lag behind. Modernizr makes it easy for you to write conditional JavaScript and CSS to handle each situation, whether a browser supports a feature or not. It’s perfect for doing progressive enhancement easily.
Boilerplate: http://html5boilerplate.com/ (If this is the one you are referring to)
HTML5 Boilerplate helps you build fast, robust, and adaptable web apps or sites. Kick-start your project with the combined knowledge and effort of 100s of developers, all in one little package.
Basically this gives you a framework for laying out your webpages so you don't have to start from scratch every time.
Normalize.css: http://necolas.github.io/normalize.css/ (Again, assuming this is the one you're talking about)
Normalize.css makes browsers render all elements more consistently and in line with modern standards. It precisely targets only the styles that need normalizing.
Basically, this CSS file allows you to write standard CSS and then it helps to render it consistently in all browsers.
TL;DR Version
These frameworks/files make it so that you can focus on writing standard-compliant website code (HTML5, CSS or JS) without having to worry about browser-specific tweaks. In addition, a front-end framework like Boilerplate gives you some nice "style-helpers" to make your website look great from the start.
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
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.