JavaScript how do you get a class off an element in Angular? change class element angular,add class element angular 2,add

<div class="js-show-more">
    <p class="app-light-text">
         The factors of a number are all the numbers that divide into it. The highest common factor, HCF, of two
         or more numbers is the highest factor that divides into all the numbers. For example, what is the highest
         common factor of 24 and 36? The answer is 12. 12 is a factor of both 24 and 36 and it is the highest
         factor that they have in factors of a number are all the numbers that divide into it. The highest common factor, HCF, of two
         or more numbers is the highest factor that divides into all the numbers. For example, what is the highest
         common factor of 24 and 36? The answer is 12. 12 is a factor of both 24 and 36 and it is the highest
         factor that they have in common
    </p>
    <a ng-click="toggle($event)" class="js-show-more-toggle"></a>
</div>

// JS
scope.toggle = function (e) {
    console.log(scope);
    // $(e).parents('.js-show-more').toggleClass('open');
};

I'm trying to get the current class so I can then get the class above to add the class open to it.

What is the best way to do this?

So .js-show-more has the class .open when class .js-show-more-toggle is clicked. I need this to work for duplicates of this code.

Answer:1

You should know the class based on a variable.

<div class="js-show-more" ng-class="{open:isOpen}>
    <p class="app-light-text">...</p>
    <a ng-click="isOpen = !isOpen" class="js-show-more-toggle"></a>
</div>


If using ng-repeat it gets even easier since ng-repeat automatically creates isolate scopes. See example below:

<div class="js-show-more" ng-repeat="item in items" ng-class="{open:item.isOpen}">
    <p class="app-light-text">...</p>
    <a ng-click="item.isOpen = !item.isOpen" class="js-show-more-toggle"></a>
</div>

Simply extend each isolate scope!

Answer:2

I’m trying to modify a vector map with values obtained by AJAX and JSON. Map function perfect with this array key value: var visitorsData = { "tac": 564, "moq": 400, "lim": 1000, "...

I’m trying to modify a vector map with values obtained by AJAX and JSON. Map function perfect with this array key value: var visitorsData = { "tac": 564, "moq": 400, "lim": 1000, "...

  1. php build array key value
  2. javascript build array key value
  3. http_build_query array key

So I have this situation where I have two views. One view takes several inputs from the user, the second view shows the results of the inputs after performing some calculations. Since both the views ...

So I have this situation where I have two views. One view takes several inputs from the user, the second view shows the results of the inputs after performing some calculations. Since both the views ...

I have a gulp.task 'scripts' that uses gulp-uglify. Then I also added gulp-import and it didn't work. If i do only uglify it works. If I do only import it works. But if i do both at the same time it ...

I have a gulp.task 'scripts' that uses gulp-uglify. Then I also added gulp-import and it didn't work. If i do only uglify it works. If I do only import it works. But if i do both at the same time it ...

  1. include gulp in package.json

I am working on Google Spreadsheet's project where I am adding/deleting TimeBased triggers through scripting. All triggers fired will run one function, which will check its Id and run function ...

I am working on Google Spreadsheet's project where I am adding/deleting TimeBased triggers through scripting. All triggers fired will run one function, which will check its Id and run function ...

  1. google script trigger on form submit
  2. google script trigger not working
  3. google script trigger on change
  4. google script trigger limit
  5. google script trigger quota
  6. google script trigger time
  7. google script trigger onedit
  8. google script trigger
  9. google script trigger tutorial
  10. google script trigger installable
  11. google apps script trigger programmatically
  12. google apps script trigger
  13. google apps script trigger on form submit
  14. google sheets trigger script
  15. google script email trigger
  16. google script create trigger
  17. google apps script trigger edit
  18. google apps script trigger seconds
  19. google apps script trigger source
  20. google script get trigger