1

In my code, I did

element.attr('class', element.attr('class') + ' state-active');

and the class .state-active got added to the element.

But when I try

element.addClass('state-active');

nothing happens.

It doesn't work, doesn't matter if I get the element with any of those:

var element = $('.state');
var element = angular.element($('.state'));
var element = angular.element($('.state')[0]);

I tried everything I could imagine, but none was enough. I noticed that .css() doesn't work either.

What could cause this issue and how do I solve this? For now my code is working, but that solution is not elegant...

1
  • 1
    Please try and reproduce it in a jsfiddle or plunker. Commented Jan 23, 2015 at 14:14

1 Answer 1

2

Rather than using jQuery, try to approach the problem from a different angle (no pun intended!) such as using ngClass. This allows you to set classes according to conditions using data binding. It's usually better that way, letting Angular do the nuts&bolts of actually changing the DOM.

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

1 Comment

Indeed, that sounds better. I'll change the code to do that!

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.