1

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).

My Code:

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.

3
  • your jsfiddle has error Commented Jul 14, 2013 at 9:55
  • @ebramtharwat just saw it! can you solve it? please tell me? Commented Jul 14, 2013 at 9:55
  • the error is here if () $obj.first().insertAfter($obj.last());, do u see the empty () after if ? what's yr condition Commented Jul 14, 2013 at 9:57

2 Answers 2

2

$obj.find(':not(:last-child)') should work

Sign up to request clarification or add additional context in comments.

Comments

1

$obj.not(':last') should be your target.

But I don't understand your if statement.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.