#464 ✓resolved
Douglas Fraser

Selector.handlers.id not finding elements when root is not in DOM

Reported by Douglas Fraser | November 26th, 2008 @ 08:18 AM | in 1.6.1

This applies only for IE (IE 6, I have not tested in IE 7). Prototype I was using Element.select as a way to extract descendant elements from a temporary Element for further processing. Because the root is temporary, the code does not insert it into the DOM.

Javascript was throwing a 'undefined' error and I traced it to Selector.handlers.id -

    id: function(nodes, root, id, combinator) {
      var targetNode = $(id), h = Selector.handlers;
      if (!targetNode) return [];
      if (!nodes && root == document) return [targetNode];

All of the arguments to the id() function (used in match()) were correct; the issue lies in the fact that the targetNode is assumed to be in document (the $()) so the targetNode is never actually found despite being in the nodes[] array.

The obvious fix would be brute force search nodes[] for the element with id 'id', but I am not aware of how id() is used elsewhere. The workaround is to insert any temporary root elements into document so the targetNode is found.

Firefox uses the XPath related code rather than match() so it works fine.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

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

The Prototype JavaScript library.

Shared Ticket Bins

Referenced by