It's preferable correct the invalid markup and use the selector you have chose or ( $(".u li:last-child").

E > F selects all elements F that are descendants of E element.
E F selects all elements F that are children (direct descendants) of E element.

Mantra: Validate! Validate! and Validate!
http://validator.w3.org/

You may want to move that child ul inside an li - it's not proper HTML
to put a UL inside a UL.

--John

On 28 Okt., 13:07, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
Hi everyone,

I have a question on JQuery selector. I want to add a class, last,
into li elements where have <!-- This is the one --> comment next to
it under different ul but have the same class "u".

This is what I ended up with. However, it only selects "li" final two.
$(".u > li:last-child").addClass("last");

<body>
        <div id="d1">
                This is content
        </div>
        <ul class="u">
                <li>1</li>
                <li>2</li>
                <li>final one</li> <!-- This is the one -->
                <ul class="l">
                        <li>11</li>
                        <li>22</li>
                </ul>
        </ul>
        <ul class="u">
                <li>3</li>
                <li>4</li>
                <li>final two</li> <!-- This is the one -->
        </ul>
</body>

Any help will be appreciated. Thanks.

Reply via email to