Matt
Matt

Reputation: 2815

jQuery: Select to find last li of nested lists

I am looking for a jQuery selector to find the last li of several nested lists. The structure will be deeper than this in reality, but I figure a selector that could get these two should probably work.

<ul>
  <li>
    <a>some link</a>
    <ul>
      <li>
        <a>not this one</a>
      </li>
      <li>
        <a>this one</a>
        <ul>
          <li>
            <a>also not this one</a>
          </li>
          <li>
            <a>and this one too</a>
          </li>
        </ul>
      </li>
    </ul>
  </li>
</ul>

Upvotes: 0

Views: 1504

Answers (1)

Rob W
Rob W

Reputation: 348972

$('li:last-child > a');

Will select every <a> element, which is a child of the last <li> of every <ol> or <ul> list.

Demo: http://jsfiddle.net/Et5wv/

Upvotes: 1

Related Questions