0

After goggling for a day on "how to do DOM selection through AngularJs", i found something like this

var elem = angular.element(document.querySelector("#myDiv"));
elem.removeClass("selected");

but not sure whether AngularJs have something better than this to handle the DOM without using JQuery (because my project only need basic DOM selection).

  • depends on use case. A custom directive exposes the element as a jQlite object that allows use of many of jQuery methods – charlietfl Sep 14 '14 at 15:30
  • you are not finding it because, it should not be done this way when you are using angularjs. you would never need dom selector with angularjs... always do it with directives – harishr Sep 14 '14 at 15:40

1 Answers1

0

If your project only needs basic DOM selection, why use AngularJS? (If you're new to Angular, check out this answer)

For simple DOM selection, you can just use vanilla javascript - it appears you aldready know about querySelector so I find your question sort of vague. You can use classList for css class manipulation.

For your posted code you could simply do:

var elem = document.querySelector("#myDiv");
elem.classList.remove("selected");
Community
  • 1
  • 1
xec
  • 17,349
  • 3
  • 46
  • 54