tags:

views:

1602

answers:

3

Hi,

I have this HTML

  <div id="navContainer">
    <ul>
      <li class="selected"><a href="#">Home</a></li>
      <li><a href="#">Services</a></li>
    </ul>
  </div>

And I want to change the top border of the li next to the selected one (in this case 'Services'). I have this jQuery but it does not work.

$(document).ready(function(){
  alert($("#navContainer .selected").next().html()); // This alerts: <a href="#">Services</a>
  $("#navContainer .selected").next().css("border-top-color","#7d7d7d"); // This doesn't do anything
});

Am I doing something wrong?

Thanks in advance!

+1  A: 

Are you trying to change the top border or the background color? Fix your question.

Your example works for me. Here's my full test:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html>
<head>
<script type="text/javascript" src="jquery-1.3.1.js"></script>
<script>
$(document).ready(function(){
  alert($("#navContainer .selected").next().html()); // This alerts: <a href="#">Services</a>
  $("#navContainer .selected").next().css("background-color","red");
});
</script>
</head>
<body>
  <div id="navContainer">
    <ul>
      <li class="selected"><a href="#">Home</a></li>
      <li><a href="#">Services</a></li>
    </ul>
  </div>
</body>
</html>

The second element's background color turns red.

Crescent Fresh
Sorry I changed it to background color to test if it would work but I forgot to change it back. Turned out to be the .js file.
+1  A: 

This works for me, the background-color of the Services-LI is changed to red.

If you want to change the top-border, replace

.css("background-color", "red");

with

.css("border-top","solid 1px red");
M4N
+1  A: 

Looks ok to me, maybe your <a> link also defines a background-color which covers the one you set on the <li>, that could be why you cannot see anything.

I suggest you check the CSS styles using the Firebug extensions for Firefox.

Vincent Robert
It turned out to be my .js file! I downloaded the production version and it works! I used the Visual Studio version before, also downloaded from jquery.com.Sorry everyone, you're right there is nothing wrong with the code.