Bug Tracker

Opened 13 years ago

Closed 13 years ago

#1111 closed bug (invalid)

IE7 bug for $(expr, context) ;

Reported by: geekinabox Owned by:
Priority: major Milestone: 1.1.4
Component: core Version: 1.1.3
Keywords: Cc:
Blocked by: Blocking:

Description (last modified by john)

This barebones fails in my IE7:

var html1 = "<result>test</result> " ;
$("result",html1).text() ;

... IE informs me that "object doesn't support this property or method" on the selector ... it doesn't like the 'html1' context (or any context).

Something like this works (IOW, no error), but obviously doesn't fit the bill:

var html1 = "<result>test</result> " ;
$("result").text() ;

...sorry if this is a repeat ... i looked @ prev tickets.

Change History (4)

comment:1 Changed 13 years ago by john

Resolution: worksforme
Status: newclosed

I'm not really sure what you're trying to achieve, considering that <result> is not valid HTML nor is HTML a valid context. If I had to guess as to why an error was occurring, it's because you have an extra space at the end of your string (jQuery is only designed to work with elements - anything else will cause an error). In the end, however, your query won't match any results since the result element isn't a child of itself.

I think this is what you might be trying to achieve (but I'm not entirely certain:

  $(html1).text();

that should give you "test" as a result.

comment:2 in reply to:  1 ; Changed 13 years ago by geekinabox

Resolution: worksforme
Status: closedreopened

Replying to john:

john ... sorry if I didn't give enough detail/intent ... I was trying to keep it simple. My specific situation is that I have XML being returned from an ajax call. I want to parse that xml for a particular result. (obviously, then, I'm not dealing w/ html elements here).

Here's a revised example that, again, works in firefox, but not IE ...

	var xmldata = "<result><success>true</sucess><message>test</message></result>" ;
	alert($("result message",xmldata).text()) ;

The intent, to be clear, is the find the message element and output its content text.

Am I wrong in expecting this to work? Are jquery selectors for html docs/elements only, or are other XML docs valid targets, too? Am I correct in thinking that I should be able to target this random XML blob with a selector? Again, the fact that it works in firefox makes me thing I'm not crazy here, but maybe that's just a lucky coincidence (i.e., it works, but not by design).

The fact that the jquery documentation for '$( expr, context )' contains this comparable example (selecting against a XML doc):

$("div", xml.responseXML)

... makes me think that this should work.

I'll reopen this one last time ... if I'm off-base let me know and I'll let it go.

Thanks.

(I'm also experiencing this on IE6 on a separate machine)

comment:3 in reply to:  2 Changed 13 years ago by geekinabox

Replying to geekinabox: (pardon the typ0 in the XML) ... fixed in and problems remains:

	var xmldata = "<result><success>true</success><message>test</message></result>" ;
	alert($("result message",xmldata).text()) ;

comment:4 Changed 13 years ago by john

Description: modified (diff)
Milestone: 1.1.31.1.4
Resolution: invalid
Status: reopenedclosed
Version: 1.1.21.1.3

The problem is that jQuery doesn't provide any mechanisms for parsing XML; xml.responseXML is actually a DOM Document (already pre-parsed) which is why we can handle it. Sorry for the confusion.

Note: See TracTickets for help on using tickets.