Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9114 (closed defect: fixed)

Opened 1 year ago

Last modified 9 months ago

getElementsBySelector does'nt return a document-ordered array

Reported by: balthazar Assigned to: sam
Priority: high Milestone: 2.x
Component: Prototype Version: edge
Severity: major Keywords:
Cc:

Description

In the documentation for getElementsBySelector it is written:

Takes an arbitrary number of CSS selectors (strings) and returns a document-order array of extended children of element that match any of them.

The result is not document-ordered.

Change History

07/27/07 04:27:18 changed by balthazar

  • summary changed from getElementsBySelector does'nt return a document-order array to getElementsBySelector does'nt return a document-ordered array.

11/01/07 02:22:30 changed by brownstone

This code may help you. I lifted it from PPK's QuirksMode.org and stuck it in a generic function:

function sortByDocOrder(list) {
	var testNode = list[0];
	// IE doc-order
	if (testNode.sourceIndex) {
		list.sort(function (a,b) {
			return a.sourceIndex - b.sourceIndex;
		});
	}
	// W3C doc-order
	else if (testNode.compareDocumentPosition) {
		list.sort(function (a,b) {
			return 3 - (a.compareDocumentPosition(b) & 6);
		});
	}
}

01/18/08 04:40:51 changed by savetheclocktower

  • status changed from new to closed.
  • resolution set to fixed.

Thanks for pointing this out. I've updated the documentation.