Skip to main content

Bug Tracker

Side navigation

#5543 closed bug (invalid)

Opened November 23, 2009 02:47PM UTC

Closed November 20, 2010 02:12PM UTC

Last modified December 19, 2011 10:24PM UTC

Pseudoelements :last-of-type and :first-of-type broken in certain contexts.

Reported by: Emmett Owned by: john
Priority: minor Milestone: 1.4
Component: selector Version: 1.3.2
Keywords: psuedoelement Cc:
Blocked by: Blocking:
Description

With markup:

<table id="mytable">
    <tbody>
        <tr class="one">
            <td></td>
        </tr>
        <tr class="two">
            <td></td>
        </tr>
    </tbody>
</table>

This works properly:

$("#mytable tbody > tr:last-of-type");  // [ tr.two ]

But this will return all the tr nodes:

$("tbody >tr:last-of-type", "#mytable"); // [ tr.one, tr.two ]

So will this:

$("#mytable tbody").children("tr:last-of-type"); // [ tr.one, tr.two ]

:last-child works in all of these cases.

:first-of-type exhibits the exact same broken behaviour.

Attachments (0)
Change History (3)

Changed November 23, 2009 04:43PM UTC by pbcomm comment:1

There is no selector :last-of-type, it's :last or :first

Changed November 20, 2010 02:12PM UTC by dmethvin comment:2

resolution: → invalid
status: newclosed

jQuery doesn't support a :last-of-type selector across browsers, it's not in the API documentation. The selector may work if the browser supports querySelectorAll but it's not in Sizzle.

Changed December 19, 2011 10:24PM UTC by anonymous comment:3

Actually, Resig removed support for this along with a host of other selectors that *were* in jQuery in the past. I don't know why people with bug-moderation privileges wouldn't know about this.