Question

I can not change the color of the text with js. Showing and Hiding div tags are working great but color can't be changed. btw, in my css file there are no styles for those links.

HTML:

    <ul>
    <li id="web_link"><a href="#">WEB</a></li>
    <li id="design_link"><a href="#">DESIGN</a></li>
    <li id="photo_link"><a href="#">PHOTO</a></li>
    </ul>

<div id="web_proekti">
 Some elements
</div>

<div id="design_proekti">
Some elements 
</div>  

<div id="photo_proekti">
Some elements 
</div>

Javascript file:

$('#web_link').click(function()
{
    $('#web_proekti').show();
    $('#design_proekti').hide();
    $('#photo_proekti').hide();
    $('#design_link').css('color','#999');
    $('#photo_link').css('color','#999');

}
);

$('#design_link').click(function()
{
    $('#design_proekti').show();
    $('#web_proekti').hide();
    $('#photo_proekti').hide();
    $('#web_link').css('color','#999');
    $('#photo_link').css('color','#999');

}
);

$('#photo_link').click(function()
{
    $('#photo_proekti').show();
    $('#design_proekti').hide();
    $('#web_proekti').hide();
    $('#design_link').css('color','#999');
    $('#web_link').css('color','#999');

}
);
Was it helpful?

Solution

You are changing color of the <li>, but not the link color.

To change the color of the <a>, try

 $('#photo_link a').css('color','#999');

instead of

 $('#photo_link').css('color','#999');

OTHER TIPS

You have to change the color from the <a> tag itself by adding a simple a after its parent id in the js:

$('#web_link').click(function()
{
    $('#web_proekti').show();
    $('#design_proekti').hide();
    $('#photo_proekti').hide();
    $('#design_link a').css('color','#999');
    $('#photo_link a').css('color','#999');

}
);

$('#design_link').click(function()
{
    $('#design_proekti').show();
    $('#web_proekti').hide();
    $('#photo_proekti').hide();
    $('#web_link a').css('color','#999');
    $('#photo_link a').css('color','#999');

}
);

$('#photo_link').click(function()
{
    $('#photo_proekti').show();
    $('#design_proekti').hide();
    $('#web_proekti').hide();
    $('#design_link a').css('color','#999');
    $('#web_link a').css('color','#999');

}
);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top