0

In JavaScript one can change class of an element like this

document.getElementById("MyElement").className = "MyClass";

What is the alternative for doing something similar in AngularJS function? I am getting an element by using

var myElement = angular.element( document.querySelector( '#MyElement' ) );

now is there any way to change class of var myElement? or is it possible to do something similar to myElement.style ?

3
  • 2
    read about ng-class on official angular docs site Commented Jan 20, 2014 at 6:06
  • 1
    @AjaySingh I did, I even changed the css of that element using ng-class but that method is too lengthy. if there is an alternative for the method i asked above, it will be most efficient Commented Jan 20, 2014 at 6:08
  • Share your html and js controller code and Also look at ng-class Commented Jan 20, 2014 at 6:08

1 Answer 1

2

Angular provides a jqLite implementation of jQuery. There are also funcitons available like

  • addClass,
  • removeClass
  • toggleClass.

Full spec: http://docs.angularjs.org/api/angular.element

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.