Jquery Find an XML element based on the value of one of it's children
- by NateD
I'm working on a simple XML phonebook app to learn JQuery, and I can't figure out how to do something like this:
When the user enters the first name of a contact in a textbox I want to find the entire record of that person. The XML looks like this:
<phonebook>
<person>
<number> 555-5555</number>
<first_name>Evelyn</first_name>
<last_name>Remington</last_name>
<address>Edge of the Abyss</address>
<image>path/to/image</image>
</person>
<person>
<number>+34 1 6444 333 2223230</number>
<first_name>Max</first_name>
<last_name>Muscle</last_name>
<address>Mining Belt</address>
<image>path/to/image</image>
</person>
</phonebook>
and the best I've been able to do with the jQuery is something like this:
var myXML;
function searchXML(){
$.ajax({
type:"GET",
url: "phonebook.xml",
dataType: "xml",
success: function(xml){myXML = $("xml").find("#firstNameBox").val())}
});
}
What I want it to do is return the entire <person> element so I can iterate through and display all that person's information. Any help would be appreciated.