views:

76

answers:

1

I'm trying to parse a simple xml document with jQuery. Does anyone know why the following works fine in Chrome and Firefox but not in Internet Explorer (7 and 8)?

var selBunit = $("#bunit").val();
$(bunitXml).find('bunit bname:contains('+selBunit+')').parent().find('team')

Below is a snippet of the xml. So basically I'm trying to return all "team" elements for the selected business unit ("bunit").

<bunit>
<bname>Unit 1</bname>
<teams>
    <team>
        <name>Team 1</name>
        <jobtitles>
            <jobtitle approval="false">Jobtitle 1</jobtitle>
        </jobtitles>
    </team>
    <team>
        <name>Team 2</name>
        <jobtitles>
            <jobtitle approval="false">Jobtitle 2</jobtitle>
        </jobtitles>
    </team>                         
</teams>
</bunit>

At first I tried

$(bunitXml).find('bunit bname:contains($("#bunit").val())').parent().find('team')

which doesn't work at all. After some googling I tried the following:

var selBunit = $("#bunit").val();
$(bunitXml).find('bunit bname:contains('+selBunit+')').parent().find('team')

which returns all team elements fine in Chrome and Firefox but not in Internet Explorer. I can't get my head around it. I'm pretty new to jQuery so I might go about it completely wrong so any suggestions would be appreciated. Thanks a bunch

A: 
var selBunit = $("#bunit").val();
$(bunitXml).find('bunit bname:contains('+selBunit+')').parent().find('team')

If I m understanding well, selBunit is a string so you should use :

var selBunit = $("#bunit").val();
$(bunitXml).find("bunit bname:contains('"+selBunit+"')").parent().find('team')

or

 $(bunitXml).find("bname:contains('" +selBunit+ "')").find('team');
RafH