t = t.substr(2,t.length);
// And the / root expression
- } else if ( !t.indexOf("/") ) {
+ } else if ( !t.indexOf("/") && !context.ownerDocument ) {
context = context.documentElement;
t = t.substr(1,t.length);
if ( t.indexOf("/") >= 1 )
m = re2.exec(t);
}
+ var last = ret[ret.length-1];
+
// Try to do a global search by ID, where we can
- if ( m[1] == "#" && ret[ret.length-1].getElementById ) {
+ if ( m[1] == "#" && last && last.getElementById ) {
// Optimization for HTML document case
- var oid = ret[ret.length-1].getElementById(m[2]);
+ var oid = last.getElementById(m[2]);
+
+ // Do a quick check for the existence of the actual ID attribute
+ // to avoid selecting by the name attribute in IE
+ if ( jQuery.browser.msie && oid && oid.id != m[2] )
+ oid = jQuery('[@id="'+m[2]+'"]', last)[0];
// Do a quick check for node name (where applicable) so
// that div#foo searches will be really fast
- ret = r = oid &&
- (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];
+ ret = r = oid && (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];
} else {
// Pre-compile a regular expression to handle class searches