简体   繁体   English

定位变量,然后使用CSS选择器

[英]Targetting a variable and then using CSS Selectors

I have a variable $obj which has $(".major_data .commitment_box .commitment") as its value. 我有一个变量$obj ,它的值为$(".major_data .commitment_box .commitment") No I want to use some CSS Selectors on $obj . 不,我想在$obj上使用一些CSS选择器。 How can I use them? 我该如何使用它们?

Selectors I want to use: :not(:last-child) . 我要使用的选择器:not(:last-child)

My Code: 我的代码:

HTML: HTML:

<div class="major_data">
    <div class="commitment_box">
        <div class="commitment">
            <p>Alex:</p>
            <p>He's works great.</p>
        </div>
        <div class="commitment">
            <p>Alex 1:</p>
            <p>He's works great.</p>
        </div>
        <div class="commitment">
            <p>Alex 2:</p>
            <p>He's works great.</p>
        </div>
        <div class="commitment">
            <p>Alex 3:</p>
            <p>He's works great.</p>
        </div>
        <div class="commitment">
            <p>Alex 4:</p>
            <p>He's works great.</p>
        </div>
    </div>
</div>

CSS: CSS:

.major_data .commitment_box {
    text-align: center;
    height: 40px;
    overflow: hidden;
}
.major_data .commitment_box .commitment p {
    display: inline-block;
}
.major_data .commitment_box .commitment p:first-child {
    font-weight: bold;
    margin-right: 20px;
}

JS: JS:

function tick() {
    var $obj = $(".major_data .commitment_box .commitment");
    $obj.first().delay(1000).fadeOut(function () {
        $obj.first().insertAfter($obj.last());
        tick();
    });
}
tick();

Result: 结果:
Demonstration 示范

My Question: 我的问题:
I want to target the :not(:last-child) of the $obj . 我想定位$obj:not(:last-child) I know I can do that by simply writing that whole big value of $obj but is that possible only using the variable $obj ? 我知道我可以通过简单地写入$obj整个大值来做到这一点,但是使用变量 $obj吗?

Thanks in advance. 提前致谢。

$obj.find(':not(:last-child)')应该可以工作

$obj.not(':last') should be your target. $obj.not(':last')应该是您的目标。

But I don't understand your if statement. 但是我不明白你的if陈述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM