开发者

changing the color of a link

开发者 https://www.devze.com 2023-03-18 12:30 出处:网络
I want to change the accordion based on clicking a link .It is working fine.The demo is shown in the following link http://jsfiddle.net/kufi/qp5Mg/

I want to change the accordion based on clicking a link .It is working fine.The demo is shown in the following link http://jsfiddle.net/kufi/qp5Mg/

Now,I want to change the color of link that clicked(here from red to green).If I click a link it is changing from red to green .If i Click second link the first link remains in green on开发者_Go百科ly,It should be changed to red.

Thanks in advance


$(".accordion-opener").click(function(e) {
    $(".accordion-opener").removeClass('green');
    $(this).addClass('green');
    e.preventDefault();
});

Make use of the addClass and removeClass, Demo:

http://jsfiddle.net/qp5Mg/2/


You should add:

<style>
  .clicked{
    color: green;
  }
</style>

And, in js:

$(".accordion-opener").click(function(){
  ...
  $(this).addClass("clicked");
});

EDIT: I've updated your fiddle with this code and is working OK: http://jsfiddle.net/qp5Mg/6/

Hope this helps. Cheers

0

精彩评论

暂无评论...
验证码 换一张
取 消