I have a variable $obj
which has $(".major_data .commitment_box .commitment")
as its value. No I want to use some CSS Selectors on $obj
. How can I use them?
Selectors I want to use: :not(:last-child)
.
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:
.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:
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
. I know I can do that by simply writing that whole big value of $obj
but is that possible only using the variable $obj
?
Thanks in advance.
$obj.find(':not(:last-child)')
应该可以工作
$obj.not(':last')
should be your target.
But I don't understand your if
statement.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.