Ryan Ryan - 1 year ago 85
Javascript Question

How to parse xml attributes with jQuery alone?

I'm already parsing xml successfully but i'm stuck at getting an attribute of childrens.

XML Example:

<media:thumbnail url="blah" />

Javascript/ jQuery:

$.get('data.xml', function(d){
var $entry = $(this);
var pic = $entry.find('media:thumbnail').attr('url');

That javascript doesn't work for me to get an attribute.
What's the problem?

Answer Source

Aah, namespaces are a different kind of animal, it wasn't in your original post. You have to escape the : in your selector.

var pic = $entry.find('media\\:thumbnail').attr('url');


See also jQuery XML parsing with namespaces

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download