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.
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 3 years ago.
Improve this question
I often heard that it is bad idea to combine react and jquery but I think it is more easier for me to make change on DOM with jQuery
Example:
<a className="toggleLink">Click Here to toggle Menu</li>
<div className="contentToToggle">content to toggle</div>
For jquery, I will write to function extend then I can use again for many cases or I can use click event directly by class. This class will also used again.
jQuery.fn.extend({
toggle: function(element){...}
});
but in react, I feel quite complex, each click on each component, I have to make a state to return for that component only.
Expose that I have 10 click events: First to toggle, second to addClass, third for showing popup...
So it should be bad idea to use React in this case. Is it right?
I want someone here can help me with this situation. Thanks
It is always preferred to not mix React and JQuery and it might make things more complicated.
Both of them have different ideologies. JQuery modifies actual DOM whereas React plays around with Virtual DOM.
Coding things with React may seem little bit heavy and cumbersome initially but it keeps things much more clear and less abstract going forward. Hope this helps !
No no no no no and some more no 😉😂
They are two different approaches to building a web app. Using JQuery means React could no longer be handling state, events and UI rendering. Which can causes conflicts, almost like two builders trying to build the same road at the same time using different materials and approaches.
If you using React you should use React's approach to manipulating and updating the DOM. That being said you don't have to use React if you don't want to. If you're familiar with JQuery build the site the way you know how if that will get it done quicker and React is not a requirement.
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
What kind of conflicts happen when both Jquery and AngularJS are used together ?
Angular is a framework. jQuery is a library for working with DOM. Only one of components of Angular framework called directive work with DOM, and they do use jQuery to do that. Actually, it uses its subset called jqLite. It's a personal choice whether you should use jQuery for manipulating DOM in custom directives or not, but since Angular itself uses it, I see no reason to not use it. And certainly, there will be no conflicts when Angular and jQuery are used together. In fact, Angular checks whether jQuery is available and uses it manipulate DOM intead of its built-in library jqLite.
If you're talking about whether in your custom directive's template you should use ng-class instead of adding classes to DOM elements manually, I would advice to use Angular's standard directive ng-class.
According to all best practices, the only place where you can manipulate DOM is from directives. And since you can't modify standard directive, custom directives is the only place where you can manipulate DOM. It's certainly bad practice to manipulate DOM inside controllers or services, regardless of whether you use jQuery or not.
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 4 years ago.
Improve this question
I am new to AngularJS framework and I am trying to get slide effect same as jQuery provides, I did google too much but didn't find anything related to it. So if any one has any idea about that please guide me to achieve that thank you.
You might find AngularUI useful if you want to animate DOM object insertion (check the animate directive).
---- Update -----
Newer versions of Angular (1.1.4+ I believe) add a ngAnimate directive especially made for adding CSS animation to Angular apps. Check the offical docs (http://code.angularjs.org/1.1.4/docs/api/ng.directive:ngAnimate) or http://www.nganimate.org/.
You can (and should) use the jQuery slide, but wrap it in an angular directive. Check the docs about directives and also this video.
In general, you should not be using jQuery directly with Angular, even in directives. It is a last resort. Here is another good post on the topic here on SO.
"Thinking in AngularJS" if I have a jQuery background?
In my humble opinion ui.bootstrap covers this issue, for instance this basic example http://surecode.me
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.