views:

20

answers:

2

I have scss than looks something like

#container{
   a{
      color:white;
   }
}

And I would like to change the links to another color using javascript. IE

function changeColorTo(color){
   //insert help here
}

Thanks.

+1  A: 

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.

lincolnk
This changes all the links on the entire page. Which i guess i useful, but what I really need is to change only the links in the #container section.
Ben
sorry, i overlooked that part. i updated my answer to address that.
lincolnk
+1  A: 

Solution from lincolnk works prefectly, however if using jQuery this also works

$('#container a').css('color',color)

So, yeah, jQuery is kind of sweet.

Ben