jquery addClass 找不到 css 类

标签 jquery css addclass

喂!我的赔率 DIV 上有一个点击事件,它应该编辑我的背景颜色、奇数、名称和值 div 的字体等!!

奇数 div 的变化有效,但子 div 无效!!!

    <div class="oddspanel ui-grid-a">
        <div class="description ui-block-a">
            Description
        </div>
        <div class="odd ui-block-b">
            <div class="name">
                Name
            </div>
            <div class="value">
                1,40
            </div>
        </div>
    </div>

这是我的脚本代码:

    $(".odd").click(function(){
        $(this).removeClass("odd").addClass("odd-active");
        $(this).children(".name").removeClass("name").addClass("name-active");
        $(this).children(".value").removeClass("value").addClass("value-active");
    });

我的 CSS 代码:

.odd .name {
width: 100%;
height: 15px;
line-height: 15px;
text-align: center;
font-size: x-small;
color: white;
 }

.odd .value {
width: 100%;
height: 25px;
line-height: 25px;
text-align: center;
color: #FFFF66;
  }

.odd .name-active {
 width: 100%;
 height: 15px;
 line-height: 15px;
 text-align: center;
 font-size: x-small;
 color: #9a9a9a;
 }

.odd .value-active {
width: 100%;
height: 25px;
line-height: 25px;
text-align: center;
color: #000000;
}

如果我删除之前的 .odd,例如 .value-active,它会起作用!!!但我想把它作为 child 放在 .odd 的 css 中!!!

最佳答案

由于删除了 odd 并添加了 odd-active,因此您需要使用 odd-active 而不是 odd:

.odd-active .value-active { /*not .odd .value-active*/
width: 100%;
height: 25px;
line-height: 25px;
text-align: center;
color: #000000;
}

关于jquery addClass 找不到 css 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25031732/

相关文章:

php - 属性内的 If else 语句和 If else 语句内的属性

css - IE wordpress 导航样式在登录时完美,但在注销时不完美

javascript - 使用来自所有其他主干 View 的单击和滚动聚合模糊事件

jquery - 滑动切换问题

javascript - 如果 Facebook 评论为 0,则 Conceal div

javascript - iPad 滚动 - 标题仅在滚动结束时设置为固定

javascript - 表单提交 - IE 访问被拒绝 - 同一域

javascript - touchstart 无法再滚动

javascript - jQuery 如果元素有类就做某事

jquery addClass - 等待、延迟、速度、超时或其他