This project is archived and is in readonly mode.

#1125 ✓invalid
rhill

last-of-type/nth-last-of-type fail to return proper reference

Reported by rhill | December 26th, 2010 @ 08:44 PM | in 1.3.1 (closed)

Scenario: Suppose the following snippet of HTML code:

<div id="mydiv">
blah <span class="A">blah</span> blah blah blah blah 
blah blah blah blah blah 
blah blah <span class="A">blah</span> blah blah 
blah blah blah blah blah blah blah 
blah <span class="A">blah</span> blah blah 
blah blah blah blah blah blah blah blah 
<span class="B">blah</span> blah blah blah 
blah blah blah blah blah blah blah blah 
</div>

$(mydiv).getElement('.A:last-of-type') or $(mydiv).getElement('.A:nth-last-of-type(1)') return null, instead of a reference to the last span of class A. $(mydiv).getElement('.A:nth-last-of-type(2)') returns a reference to the last span of class A, instead of a reference to the second to last span of class A.

It all works well though the the last span of class B is removed.

As expected, $(mydiv).getElement('.A:nth-of-type(3)') returns a reference to the last span of class A, and $(mydiv).getElement('.A:nth-of-type(4)') returns null.

I've written a test case to demonstrate the problem:
http://cablegate.raymondhill.net/testcase.html

Comments and changes to this ticket

  • Arian

    Arian December 26th, 2010 @ 10:27 PM

    • Milestone set to 1.3.1
    • State changed from “new” to “open”
    • Assigned user set to “Thomas Aylott”
    • Tag set to selectors, slick
    • Milestone order changed from “855” to “0”
  • Fábio M. Costa

    Fábio M. Costa December 27th, 2010 @ 12:22 AM

    • State changed from “open” to “invalid”

    this is infact the correct behavior:

    http://jsfiddle.net/fabiomcosta/BpuA3/1/

    Use a browser that supports css3 selectors to see the link.

  • rhill

    rhill December 27th, 2010 @ 02:10 AM

    Ok, it seems I misunderstood that particular selector. So the 'type' part in the name refer strictly to the element tag name, and disregard other bits such as class name (and attributes)?
    Thanks for that JsFiddle site, I didn't know about it, that should save me some times in the future.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Pages