0

I have a list of items (divs) with a button. When I click on one of this buttons I can access the element using

$event.currentTarget

that returns some thing like

<div ng-click="myFunc()">
  <i class="someclass"></i>
  <span>bla bla</span>
</div>

how can I access and elements to modify attributes like class?

2
  • Don't. Use existing directives like ng-class or ng-if etc in your html templates. Commented Jul 9, 2018 at 13:20
  • I need to do this on click... Commented Jul 9, 2018 at 13:22

2 Answers 2

1

Don't. Use existing directives like ng-class or ng-if, etc in your html templates.

<div ng-click="clicked = true">
  <span ng-class="{'someclass': clicked}">bla bla</span>
</div>

See stackblitz


Although you can get the html dom element and edit it you should only do this as a last option and other angularjs supported methods have failed or are not supported.

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

Comments

0

template

<div ng-click="myFunc($event)">
  <i class="someclass"></i>
  <span>bla bla</span>
</div>

controller

$scope.myFunc(event) {
   var elem = angluar.element(event.currentTarget);
   elem.children(".someclass").removeClass("someclass")
}

Comments

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.