使用jQuery添加CSS类onClick [英] Add css class onClick with jquery

查看:500
本文介绍了使用jQuery添加CSS类onClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人帮助我如何使用 jquery 添加 css 类吗?我已经在当前类的引导选项卡内容中添加了一个类"active".

Someone help me how to add css class with jquery? I've bootstrap tab content with the current class have a class "active".

 <div class="tab-content">
   <div class="tab-pane **active**" id="one">
      <div class="row">

我的其他标签代码是:

    <div class="tab-pane" id="two">
        <div class="row">
            <div class="col-md-12">

如果单击带有id两个的选项卡,我想在class="tab-pane"上添加active类.

if i click a tab with id two, i want to add active class on class="tab-pane".

推荐答案

这应该可以,但是boostrap已经拥有了.

This should work but boostrap already has it.

$(".tab-pane").click(function(){
      $(".tab-pane").removeClass("active"); //to remove active class from other tabs
      $("this").addClass("active"); //to add active class to clicked tab
    });

这篇关于使用jQuery添加CSS类onClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆