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