> $(".u:last > li:last").addClass("last"); Close.
$("ul.u > li:last-child").addClass("last"); 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.