Change link color with javascript for style defined by scss
I have scss than looks something like
#container{
a{
color:white;
}
}
And I would like to chang开发者_如何学编程e the links to another color using javascript. IE
function changeColorTo(color){
//insert help here
}
Thanks.
you can apply a style locally on an element and it will override the stylesheet rule.
function changeColorTo(color){
var container = document.getElementById('container');
var anchors = container.getElementsByTagName('a');
for (var i = 0; i<anchors.length; i++){
anchors[i].style.color = color;
}
}
edits: i'm dumb, i get what you want to do now. sample updated.
Solution from lincolnk works prefectly, however if using jQuery this also works
$('#container a').css('color',color)
So, yeah, jQuery is kind of sweet.
精彩评论