views:

488

answers:

4

Hi guys, need a quick help here. I have a series of hyperlinks all with the same class name. I want that when I click on anyone of the links - the background colors of all the other hyperlinks change except the link I have clicked.

+6  A: 
$('.className').click(function() {
    $('.className').not(this).css('backgroundColor', '#ccff00');
});
Alexander Gyoshev
+2  A: 

Another option here.

Jquery Visited Plugin

Define a CSS class "visited". And then..

$('#sidebar a').visited().addClass('visited');
simplyharsh
a really nice suggestion, yet he didn't ask for visited links...
Alexander Gyoshev
He had got the answer earlier. Just thought to give a suggestion of an option.
simplyharsh
A: 
$("a").onclick(function () {
  $(this).css("color");
});

With jQuery you can alter the CSS settings directly - so just build a function, choose a trigger (onclick, mouseover etc.) and you can alter the CSS settings...

Gnark
This does not answer the question.
Crescent Fresh
+2  A: 

I would create another class that has the new background color and apply it to all except the one that was just clicked.

$('.first_class').click(function(){
  $('.first_class').not(this).addClass('new_class')
});
theIV