Hello I’m just starting with jquery and don’t know why this is not working…
I want to change the color of the link after it has been clicked. When other links are clicked links should turn to be white again, the current clicked item should be yellow…but all links keep being yellow…?!
Here comes the fiddle: http://jsfiddle.net/adkWe/
<script type="text/javascript">
$(document).ready(function() {
$('.main a').click(function(){
$(this).css({"color":"#ffd601"});
$(this).siblings('a').css({"color":"#fff"});
});
});
</script>
<div id ="navigation">
<ul class="main">
<li><a href="#test1">Test1</a></li>
<li><a href="#test2">Test2</a></li>
<li><a href="#test3">Test3</a></li>
<li><a href="#test34">Test4</a></li>
</ul>
There is a simple change you can make to your current code:
$(this).parent().siblings().find('a').css({"color":"#fff"});Effectivly the
<a>s dont have simplings, so you use.parent()to move the the<li>s and select their siblings.Ive updated your fiddle
Al