0

Default a:link and a:visited background-color is transparent and color black. Then a:hover is specified with background to be black and color to be white. This works well.

Here is the problem: I inserted jquery script which performs a background and color change, in my case to set the background black and color to be white - same as the a:hover. This script is performing the wanted action but the color of the text stays black. Any help?

Here are the codes:

<ul id="subnav">
    <li><a href="http://127.0.0.1:4001/wbdemo/pages/abc.php" class=”red” onclick=”selected(this)”><h99>Home<h99/></a></li>
    <li><a href="http://127.0.0.1:4001/wbdemo/pages/asd.php"><h99>Home</h99></a></li>
    <li><a href="http://127.0.0.1:4001/wbdemo/pages/rtz.php"><h99>Home</h99/></a></li> 
    <li><a href="#"><h99>Home</h99/></a></li> 
    <li><a href="#"><h99>Home</h99/></a></li>
</ul> 

<script type="text/javascript">
$(document).ready(function(){
    $('#subnav a').each(function(index) {
        if(this.href.trim() == window.location)
            $(this).addClass("selected");
    });
});
</script>
ul
{ list-style-type: none;
  margin:0;
  padding:0;
  overflow: hidden;
}

ul a:link, ul a:visited
{ display: block;
  width: 240px;
  background-color: tranparent;
  text-align: right;
  text-transform: uppercase;
  text-decoration: none;
  height: 40px;
  color: #000000
}

ul a:hover, .selected
{ background-color: #000000;
  color: #ffffff
}

2 Answers 2

2

Split last css class into two:

ul a:hover
{ 
  background-color: #000000;
  color: #ffffff;
}

.selected
{ 
  background-color: #000000;
  color: #ffffff !important;
}

Or, simpler, just have the !important added to the last line:

ul a:hover, .selected
{ 
  background-color: #000000;
  color: #ffffff !important;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Works as it should! :)
0

try with

$(this).css('color','coloryouwant')

1 Comment

With this one every menu item got white not just the selected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.