jquery - 如何同时给元素的所有子元素添加css样式?

标签 jquery css

如:

<div class="mostOut">
    <div class="a">
        <h3 class="b"></h3>
        <div class="d"></div>
    </div>
</div>

以及如何同时将 css 样式应用于 "moustOut" 的子级。例如:

使用一个点击事件css('opacity',1) 可以应用于"a","b","d" 同时。或者,排除 "b"

最佳答案

少一点代码

$('.mostOut').click(function()
{
   $(this).children("*").css('opacity', 1);
});

并排除“.b”

$('.mostOut').click(function()
{
   $(this).children("*").not(".b").css('opacity', 1);
});

或者如果它不是导致隐藏/无的不透明度

$('.mostOut').click(function()
{
   $(this).children("*").show();
});

关于jquery - 如何同时给元素的所有子元素添加css样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4315921/

相关文章:

php - 在 jQuery 函数中使用 smarty 变量

html - jQuery 动画边框颜色

html - 删除CSS中复选框的 "box"

html - 背景覆盖背景大小

html - 网页内容在加载时闪烁/移动

html - 具有不断变化的 img 的固定大小容器的奇怪滚动行为

javascript - keydown事件中的值没有改变

jquery - 冒泡 Jquery 的 Dom

javascript - 模拟链接单击而不与 jquery 中的用户交互?

html - 在第二个框外添加第三个框