0

Is it a good idea to use jquery in angularjs directive to interact with dom elements?Thanks.

2
  • It's okay, why not. jQuery exists for DOM manipulations. Whether it's really needed or not - another question. Modern environments have pretty good support for convenient methods like querySelector(All), etc. so jQuery might not be really necessary. Commented Aug 20, 2015 at 9:38
  • Is it a good idea, some might say yes, others say no. It also depends on the situation I guess, but as @dfsq mentions, it's not necessary. AngularJS is powerfull enough to handle most of the things you can do in jQuery. Commented Aug 20, 2015 at 10:08

2 Answers 2

3

Sine the element is easily accessible in directive, you can do any DOM related operation in directive without using jQuery.

directive('yourDir', function() {
  return {
    restrict: 'E/A',
    link: function(scope, element, attrs) {
        //do your things here
     }
   }
} 

Hence overflowing code with jQuery is not a good idea in my opinion. You can do all similar operations using angular. Adding an extra library for same operations is not good. Sometimes this also leads in making application heavy since the use of JQuery will be limited to DOM manipulation. Try creating simple operation using JavaScript only

Sign up to request clarification or add additional context in comments.

Comments

1

It is okay to use JQuery in AngularJS. In fact, AngularJS allows the use by using angular.element instead of $(element) in JQuery.

You can read AngularJS Element.

However, in my experience, I was using the $(element) since it is convenient for me and I have more knowledge on JQuery accessing DOM compared to angularJS.

2 Comments

angular.element is going to be jQuery if it was loaded before Angular.
@whoknow, thanks, I have more experience in JQuery to so It`s easy to understand for me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.