开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜