2016-03-22 12 views
0

Ich werde versuchen, die Farbe eines Elements mit eckigen js zu bekommen, aber bin nicht erfolgreich. Hier ist, was ich tue:Wie bekomme ich die Farbe eines Elements mit angularjs

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); 
} 

Meine 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; 
} 

Das ist nichts für mich zurück. Bitte helfen.

+1

eine Geige wird uns helfen, mehr schneller .. :) –

+1

Hier finden Sie aktuelle https://developer.mozilla.org/en-US/docs/Web/ API/Window/getComputedStyle –

+0

Kannst du deine 'html'-Struktur auch setzen? – Thabung

Antwort

1

Sie können es mit 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') 
    }) 
} 
+0

Ehrfürchtig. Vielen Dank :) – Archana

Verwandte Themen