Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Accessing XML

Let's say I got a very complicated XML through an Ajax request and the following code is a fraction of it:

<info type="Alternative title" lang="EN">Title 1</info>
<info type="Alternative title" lang="DE">Title 2</info>
<info type="Alternative title" lang="FR">Title 3</info>
<info type="Alternative title" lang="ES">Title 4</info>

Question: How can I access for example the third title using javascript? (In short how can I select the content inside info by using lang="FR").

1 Answer

You'll probably want to use jQuery's parseXML(). You can find an example in the jQuery docs at https://api.jquery.com/jQuery.parseXML/. Then you should be able to use .find() to look through it.

Thx for the answer. So with JQuery I can do that .find('info[lang="FR"]')

But what about plain javascript?