Javascript 我可以让一个css div类模拟另一个css div类吗?

Javascript 我可以让一个css div类模拟另一个css div类吗?,javascript,jquery,css,twitter-bootstrap,Javascript,Jquery,Css,Twitter Bootstrap,我刚开始为我的网站使用引导。我喜欢它的外观,我想对大量不同的博客文章进行一些修改,以加入bootstrap风格。我不想通过数百篇文章来更改div的class元素。我可以这样做吗: <div class="important_note"> this is a old note that I want to use bootstrap styling on. </div> 这是一个我想在其上使用引导样式的旧注释。 css: .重要提示{ 模仿(.alert) } 警

我刚开始为我的网站使用引导。我喜欢它的外观,我想对大量不同的博客文章进行一些修改,以加入bootstrap风格。我不想通过数百篇文章来更改div的class元素。我可以这样做吗:

<div class="important_note">
this is a old note that I want to use bootstrap styling on.
</div>

这是一个我想在其上使用引导样式的旧注释。
css:


.重要提示{
模仿(.alert)
}
警报是一种引导样式


如果这是一个简单的问题,我很抱歉,但是我不太喜欢web开发。我也找不到任何类似的问题。谢谢你的帮助

使用css,您可以执行以下操作:

.important_note, .alert{
//styling
}
这将对重要的注释和警报类应用相同的样式,而无需“升级”CSS,如果只是向每个受影响的元素添加一个类,您可以使用一个小脚本:

[].forEach.call(document.getElementsByClassName('important_note'), function(node) {
    node.classList.add('alert');
});
jQuery等价物:

$('.important_note').each(function() {
    $(this).addClass('alert');
}

不,你不能那样做。您必须升级CSS。您可以使用jQuery将
alert
类添加到所有具有
important\u note
类的div中。您还可以使用较少的。这一点是不允许的。这将起作用,但请注意jQuery
.each()
的速度太慢了。@Phillip,这实际上取决于它运行的上下文;如果你说的是1000多个元素,也许吧。
$('.important_note').each(function() {
    $(this).addClass('alert');
}