title: jQuery XML Parsing - Return Parent Elements Of Child
body: <p>I am trying to return the parent element when searching for a child element and then display a parallel child's text.</p>
  
  <p>XML:</p>
  
  <pre><code>&lt;store&gt;
      &lt;shelf&gt;
          &lt;book&gt;
              &lt;name&gt;Book_1&lt;/name&gt;
              &lt;id&gt;1&lt;/id&gt;
          &lt;/book&gt;
          &lt;book&gt;
              &lt;name&gt;Book_2&lt;/name&gt;
              &lt;id&gt;2&lt;/id&gt;
          &lt;/book&gt;
          &lt;book&gt;
              &lt;name&gt;Book_1&lt;/name&gt;
              &lt;id&gt;3&lt;/id&gt;
          &lt;/book&gt;
      &lt;/shelf&gt;
  &lt;/store&gt;
  </code></pre>
  
  <p>jQuery:</p>
  
  <pre><code>$(document).ready(function(){
      $.ajax({
          type: "GET",
          url: "xml_file.xml",
          dataType: "xml",
          success: parseXml
      });
  });
  
  function parseXml(xml){
  
      var books = $(xml).find('name').filter(function () {
          return $(this).text() === 'Book_1';
      }).parent();
  
      for(i=0; i&lt;books.length; i++){
          $('#results').text(
              (books[i]).find('id').text()
          );
      }
  }
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;div id="results"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>So basically, if I search for a "name" with that has text "book", I want to get back 2 books. Than I want to display each book to a div with id="results". Any help would be appreciated. Thanks!</p>