tags:

views:

39

answers:

1

Hi there.

I have this code, which works:

$('.invest-port-thumb a').mouseenter(function() {
                $('#slider-name').load(this.href + ' cName');
});

Loading this XML:

<fragment>
    <cName cind="Industrial" stat="Active">ABC Company</cName>  
    <hq>Chicago, IL</hq>
</fragment>

How should I modify this code to load the cind attribute of cName?

+3  A: 

jQuery will not automatically parse the XML for you on load. But, you can use jQuery to parse the XML. Check out this page for examples: http://www.xml.com/pub/a/2007/10/10/jquery-and-xml.html. Basically, you load the XML and perform your selections and modifications like this:

Here's a demo to get you started: if you only have one fragment and one cName in your XML, it's safe to do this:

var cind = $(myXML).find("fragment cName").attr("cind");

It appears that you are using load() to load a fragment of the XML. Instead, try loading the entire XML content to a variable, and parse the cind attribute out of it using the line of code I gave you above.

EDIT:

Try this:

 $('.invest-port-thumb a').mouseenter(function() {
      $.get(this.href, function(response){
           var cind = $(response).find("fragment cName").attr("cind");
           $('#slider-name').html(cind);
      })
 });
SimpleCoder
Thanks for the quick response. But after declaring that cind variable, how can I incorporate it into the load() function syntax?
Andrew Parisi
Just edited my answer to give you one possible way of doing so.
SimpleCoder
I just posted a full example.
SimpleCoder
Holy crap it works! Wow, thanks man..(I learn so much from this site every day)
Andrew Parisi
No problem, glad it works
SimpleCoder
This works well. but for some reason, it will not work in IE...any thoughts?
Andrew Parisi
Update: This line of code: `var stat = $(response).find("fragment cName").attr("stat");` works when used, but this line doesn't: `var cName = $(response).find("fragment cName");` (Only in IE, firefox works fine)
Andrew Parisi
This line: var cName = $(response).find("fragment cName");returns a jQuery object, not a value.
SimpleCoder