0

I am being try to get the color of an element using angular js, but am unsuccessful. Here is what I am doing:

function colorApply() {
 var cardsList = document.getElementsByClassName("card-abbr");
 $timeout(function() {
  angular.forEach(cardsList, function(value) {
   var color = value.css('color');
   /*var color = value.style.color;*/
   console.log(color);
  });
 }, 1000);
}

My CSS:

.card-abbr:nth-child(1n) {
    color: #EF2525;
}
.card-abbr:nth-child(2n) {
    color: #88ba41;
}
.card-abbr:nth-child(3n) {
    color: #850057;
}
.card-abbr:nth-child(4n) {
    color: #003f60;
}
.card-abbr:nth-child(5n) {
    color: #588ba3;
}

This is returning nothing for me. Please help.

3

1 Answer 1

1

You can do it using window.getComputedStyle

function colorApply() {
  var cardsList = document.getElementsByClassName('card-abbr')
  angular.forEach(cardsList, function(el) {
    var style = window.getComputedStyle(el, null)
    var color = style.getPropertyValue('color')
  })
}
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome. Thank you :)

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.