The following script throws the error 

this.getElementsByTagName is not a function

using the current jquery release.

    $("//tr").each(function(i) {
      f = $("//td", this).text();
      alert(f);
    });

The problem appears to be in lines 869-880, where jQuery assumes that an
XPath expression that leads with "//" or "/" is always evaluated in a
document context rather than a node context. 


                // Handle the common XPath // expression
                if ( !t.indexOf("//") ) {
                        context = context.documentElement;
                        t = t.substr(2,t.length);

                // And the / root expression
                } else if ( !t.indexOf("/") ) {
                        context = context.documentElement;
                        t = t.substr(1,t.length);
                        if ( t.indexOf("/") >= 1 )
                                t = t.substr(t.indexOf("/"),t.length);
                }

 "documentElement" is undefined for a DOM node.  Do these blocks need to be
present?  Is there a reason that the descendant axis should not be evaluated
in a node context?


--------------------------------
Cut-and-paste example:

<head>
<script type="text/javascript"
src="http://jquery.com/src/jquery-latest.pack.js";>
</script>
<script type="text/javascript">
  $(document).ready(function() {
    $("//tr").each(function(i) {
      f = $("//td", this).text();
      alert(f);
    });
  });
</script>
</head>
<body>
<table><tr><td>f1</td><td>f2</td></tr></table>
</body>

-- 
View this message in context: 
http://www.nabble.com/Descendant-axis-with-node-context-tf3767593s15494.html#a10651129
Sent from the JQuery mailing list archive at Nabble.com.

Reply via email to