开发者

Set class on a tag after click

开发者 https://www.devze.com 2023-04-02 14:16 出处:网络
I have the following code. I wonna set a css class on the a tag that is clicked. But i wonna do it only in the language div. How can i do that? When i try to do it with $(\"language a\") is doesn\'t

I have the following code. I wonna set a css class on the a tag that is clicked. But i wonna do it only in the language div. How can i do that? When i try to do it with $("language a") is doesn't do anything.

<div id="wrapper">
 &l开发者_JAVA百科t;div id="language">
    <a href="#" class="">test 1</a>
    <a href="#" class="">test 2</a>
 </div>
    <a href="#" class="">No div 1</a>
    <a href="#" class="">No div 2</a>
</div>

$("a").click(function(event){
   $("a.active").removeClass("active");
   $(this).addClass("active");
});

.active {font-weight: bold; }


$( "#language a" ).click( function() {
    $( "#language a.active" ).removeClass( "active" );
    $( this ).addClass( "active" );
});
0

精彩评论

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