Bug Tracker

Opened 10 years ago

Closed 10 years ago

#5074 closed bug (fixed)

:Contains does not work with XML data in IE on 1.3.2

Reported by: khofer Owned by:
Priority: major Milestone: 1.4
Component: selector Version: 1.3.2
Keywords: contains selector Cc:
Blocked by: Blocking:

Description

Load any XML data and try to find elements with :contains and it does not work. Works fine in 1.2.6.

<script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript">

load jQuery google.load("jquery", "1.3.2");

</script> <script type="text/javascript">

$(document).ready(function() {

var x = $('<xml><data><item>Dog</item><item>cat</item></data></xml>'); var items = $(x).find("item:contains('Dog')"); alert(items.length);

});

</script>

Change History (5)

comment:1 Changed 10 years ago by yazadji

I think problem is in line 1945 (v1.3.2):

return (elem.textContent || elem.innerText || "").indexOf(match[3]) >= 0;

in IE IXMLDOMElement doesn't have properties textContent and innerText instead of he has property text.

In jQuery v1.2.6 line 1403:

contains: function(a,i,m){return a.textContent||a.innerText||jQuery(a).text()||"").indexOf(m[3])>=0;},

In this case I think jQuery(a).text() is resolving this problem.

So, I think for resolving this bug are two ways:

add
elem.text
add
jQuery(elem).text()

comment:2 Changed 10 years ago by yazadji

workaround:

$(x).find('item').filter(function(){return $(this).text() == 'Dog'});

comment:3 Changed 10 years ago by till

Seems to be a duplicate of #1612

comment:4 in reply to:  1 Changed 10 years ago by TFox

Replying to yazadji:

I think problem is in line 1945 (v1.3.2): In this case I think jQuery(a).text() is resolving this problem.

So, I think for resolving this bug are two ways:

add
elem.text
add
jQuery(elem).text()

I can confirm the following change to line #1945 corrected the issue

return (elem.textContent || elem.innerText || jQuery(elem).text() || "").indexOf(match[3]) >= 0;

comment:5 Changed 10 years ago by dmethvin

Component: unfiledselector
Resolution: fixed
Status: newclosed

Fixed in jQuery 1.4 (actually in Sizzle).

Note: See TracTickets for help on using tickets.