jQuery:你可以选择CSS规则,而不是类? [英] jQuery: Can you select by CSS rule, not class?

查看:106
本文介绍了jQuery:你可以选择CSS规则,而不是类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.container可以包含许多.components,而.components本身可以包含.containers(依次可以包含.components等等)

A .container can contain many .components, and .components themselves can contain .containers (which in turn can contain .components etc. etc.)

像这样:

$(".container .component").each(function()
{
    $(".container", this).css('border', '1px solid #f00');
});

我需要添加到大括号中的行才能选择嵌套的.containers它们的CSS宽度设置为auto?我确定这很简单,但我没有真正使用jQuery这么多。

What do I need to add to the line within the braces to select only the nested .containers that have their width in CSS set to 'auto'? I'm sure it's something simple, but I haven't really used jQuery all that much.

推荐答案

$(".container .component").each(function()
{
    $(".container", this).each(function() {
        if($(this).css('width') == 'auto')
        {
            $(this).css('border', '1px solid #f00');
        }
    });
});



<也请在这里检查宽度。

Similar to the other answer but since components can also have multiple containers, also needs the .each() check in here too for the width.

这篇关于jQuery:你可以选择CSS规则,而不是类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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