4
votes

In jquery 1.4.2 i was able to select xml residing in my html page by doing the following:

var xmlSettings = $("#xmlSettings")[0];

this is the same as:

document.getElementById("xmlSettings"); //this still works fine

In jquery 1.6.1 xmlSettings is undefined. all i did was upgrade my jquery from 1.4.2 to 1.6.1 and now this is not working.

is there a different selection that i need to do, or do i need to add a plugin?

xml in Html page:

<xml id="xmlSettings">
 <items>
        <item name="Test1">Test data 1</item>
        <item name="Test2">Test data 2</item>
        <item name="Test3">Test data 3</item>
 </items>
</xml>

thanks in advance,

[Resolved] Thanks to Felix Kling

the problem seems to be one of the following:

1) IE9 is not rendering IE8 Standards mode properly. I just recently upgraded to IE9 but my app still needs to run in IE8 Standard Mode therefore I've forced it in IIS to render in IE8 using X-UA-Compatible IE=8

2) i also updated my jquery file from 1.4.2 to 1.6.1

but it could be a combination of these things i'm not really sure anyway using normal document.getElementById("xmlSettings"); still works fine so in the mean time i'll use that but very bizarre issue. i wouldn’t be surprised if it's an IE9 issue. Or maybe i'll remain on jquery 1.4.2 for now.

3
XML inside HTML is invalid... - Felix Kling
@Felix Kling, please will you kindly elaborate on your comment above? because according DOM this is fine - zulucoda
@superbDeveloper: Have you ever validated your HTML document? HTML has a well defined set of allowed elements. Also HTML parses don't expect anything else than these and it is probably undefined what they do with those tags. - Felix Kling
if XML inside HTML is invalid, how come i can select this using normal document.getElementById("xmlSettings"); ? there's absolutely nothing wrong with this because DOM allows it. - zulucoda
@superbDeveloper: DOM is not HTML. You can represent HTML as DOM. That does not make everything that is valid in DOM valid in HTML. That browsers still parse it and add it to them is probably because they try to compensate errors. But it is still wrong. You can validate your page here: validator.w3.org - Felix Kling

3 Answers

1
votes

This is the real reason it's not working: a regression in jQuery 1.4.2.

0
votes

You probably don't need the [0] because an id is a singular value and doesn't return an object list like finding a class would.

0
votes

I've answered my own question as suggested by Arend

[Resolved] Thanks to Felix Kling

the problem seems to be one of the following:

1) IE9 is not rendering IE8 Standards mode properly. I just recently upgraded to IE9 but my app still needs to run in IE8 Standard Mode therefore I've forced it in IIS to render in IE8 using X-UA-Compatible IE=8. Also another thing about X-UA-Compatible rather use IE=EmulateIE8 not IE=8. But still even when you use IE=EmulateIE8 it still does not play nicely with jquery 1.6.1. Therefore its better to use IE9 standard mode which works fine, so busy converting code to be standard be compliant anyway better in the long run.

2) i also updated my jquery file from 1.4.2 to 1.6.1

but it could be a combination of these things i'm not really sure anyway using normal document.getElementById("xmlSettings"); still works fine so in the mean time i'll use that but very bizarre issue. i wouldn’t be surprised if it's an IE9 issue. Or maybe i'll remain on jquery 1.4.2 for now.