jquery - 添加 css 类在 jquery 中有时不起作用

标签 jquery css

我正在从颜色选择器中检测到一个类,并且想要更改标题标记的类。

// to find specific header id which having bgt css class . Detecting id from a div which have css class .ss

$(document.body).on('click', '.bgt', function(e) {
    e.preventDefault();
    id = $(this).closest('div').find('.ss').attr('id');
    var $this = $('#h'+id); 
    var $dv = $this.closest('div');
    var nstr= $dv.attr('class');
    var newstrt = nstr;
    //heder tag where I am to add class
    $("#h"+id).addClass(newstrt);

有时工作有时不工作 请帮忙

最佳答案

您应该引用要添加的类:

$("#h"+id).addClass("newstrt");

关于jquery - 添加 css 类在 jquery 中有时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21454443/

相关文章:

javascript - $.post 和 $.get 只允许更改标题,不记录日志?

javascript - jQuery 干涸功能

jquery - 通过鼠标滚轮滚动 overflow-x

html - 段落不使用左边距移动

html - 具有全宽元素的跨度样式间距

css - <li> 上的 float 不适用于绝对位置

javascript - 按属性查找 xml 元素

javascript - 谷歌加登录复选框

javascript - React 中进出 CSS 转换的不同延迟

jquery - 在 <div> 中并排显示 FadeItems