Honey Thakuria Honey Thakuria - 1 month ago 9
React JSX Question

DOM Manipulation using Angular or Jquery?

Is it a good practice to use Jquery for DOM manipulation, Animation while using a framework like Angular ? OR one should use their methods like ng-class,ng-animate ? 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.