Peter Woods schrieb:
> The current version of jQuery has trouble when trying to access methods
> such as text() or parent() or attr() inside an each statement within the
> context of an XML document. For a test case, see Bug #164
> <http://jquery.com/dev/bugs/bug/164/>. The general assumption with this
> bug has been that the problem lies in methods such as text(), and
> therefore it would be impossible to determine whether the object in
> question was an XML object or a HTML object and act on it accordingly.
> While this bug has been closed, it is crucial for what I'm using jQuery
> for, so I decided to debug it and have found a simple yet (as far as I
> can tell) effective solution to the bug which works in both IE and
> Firefox, and should work fine in other browsers as well.
>
> The problem itself does not actually lie within the text() method, but
> instead is caused by this statement within the primary jQuery function body:
>
> // Handle HTML strings
> var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
>
> As such, any time $(this) is called within the each function body the
> error is thrown, not just when specific methods such as text() or
> parent() are called. The error seems to be caused by 'a' being an object
> instead of a string and IE barfing when trying to execute the regular
> expression on 'a'.
>
> The fix is quite simple, as far as I can tell... simply replace the line
> in question with this:
>
> // Handle HTML strings
> var m;
> if (typeof a == "string") m = /^[^<]*(<.+>)[^>]*$/.exec(a);
>
> Because the regular expression should only be effective when it's
> executed on a string anyway, this prevents the IE error from being
> thrown and still preserves the functionality otherwise. In my limited
> testing so far, I have yet to find any other side effects to this.
Thank you Peter! I was also quite unhappy to see this bug closed as
wontfix. I was bothered by the same bug.
Looks like it can be fixed finally... :-)
> One last XML related fix I've found within jQuery. When using Xpath
> expressions, jQuery has a custom expression which allows matching
> against the content of an element, such as $("p:contains('test')"),
> which will match all <p> tags which contain text in their body. Once
> again, IE has trouble with this when processing it in an XML context.
> The fix is simple, change this line (~line 520):
>
> contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
>
> to this:
>
> contains: "((a.firstChild &&
> a.firstChild.nodeValue)||a.innerText||a.innerHTML).indexOf(m[3])>=0",
Does this work in Firefox with text nodes that start on a new line?
<item>
Text node
</item>
-- Klaus
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/