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

Ticket #11474: select_id_ie_patch_test.diff

File select_id_ie_patch_test.diff, 1.5 kB (added by jdalton, 7 months ago)

patch by Kangax

  • test/unit/selector.html

    old new  
    459459        Selector.matchElements($('counted_container').descendants(), 'div'), 'div.is_counted',  
    460460        'div.is_counted' 
    461461      ); 
     462    }, 
     463     
     464    testSelectorNotInsertedNodes: function() { 
     465      var wrapper = new Element("div"); 
     466      wrapper.update("<table><tr><td id='myTD'></td></tr></table>"); 
     467      new Selector('[id=myTD]').findElements(wrapper); 
     468      this.assertNotNullOrUndefined(wrapper.select('[id=myTD]')[0]); 
     469      this.assertNotNullOrUndefined(wrapper.select('td')[0]); 
     470      this.assertNotNullOrUndefined(wrapper.select('#myTD')[0]); 
    462471    } 
    463472  }); 
    464473   
  • src/selector.js

    old new  
    418418     
    419419    id: function(nodes, root, id, combinator) { 
    420420      var targetNode = $(id), h = Selector.handlers; 
    421       if (!targetNode) return []; 
     421      if (!targetNode) { 
     422        // the element might not be in a DOM yet so brute force approach 
     423        for (var i = 0, node, nodes = root.getElementsByTagName('*'); node = nodes[i]; i++) { 
     424          if (node.id == id) { 
     425            targetNode = node; 
     426            break; 
     427          } 
     428        } 
     429        if (!targetNode) return []; 
     430      } 
    422431      if (!nodes && root == document) return [targetNode]; 
    423432      if (nodes) { 
    424433        if (combinator) {