title: jquery - How do I get the attribute of the root, or top most < li > if I'm nested deeply down in an unordered list
body: <p>I want walk back up the tree menu of a nested unordered list to the top most &lt; li > and retrieve the "p_node" attribute using the toggle function of jquery.  So, for example, when I click on "Annie" I want to retrieve the root li, which in her case is "mCat1" and extract the value for "p_node" to be used in the script. How can I accomplish this?  Thanks for your help.</p>
  
  <p>Here's the unordered list:</p>
  
  <pre><code>&lt;ul id="nav&gt;
    &lt;li type="root" p_node="39"&gt;Cat 2
       &lt;ul&gt;
          &lt;li&gt;&lt;a&gt;sub cat2&lt;/a&gt;&lt;/li&gt;
       &lt;/ul&gt;
    &lt;/li&gt;
    &lt;li type="root" p_node="40"&gt;mCat1
        &lt;ul&gt;
           &lt;li&gt;Subcat A
              &lt;ul&gt;
                 &lt;li&gt;Subcat A.1
                    &lt;ul&gt;
                       &lt;li&gt;&lt;a&gt;Annie&lt;/a&gt;&lt;/li&gt;
                    &lt;/ul&gt;
                 &lt;/li&gt;
              &lt;/ul&gt;
            &lt;/li&gt;
          &lt;/ul&gt;
     &lt;/li&gt;
   &lt;/ul&gt;
  </code></pre>
  
  <p>Here's some of the jquery I've been trying. the selector is selecting the bottom most &lt; li > that has an anchor tag:</p>
  
  <pre><code>$('#nav li:not(:has(li))&gt;a').toggle(function() {
                     //show stuff
                     var parentEls = $(this).parents()
                     .map(function () { 
                    if( $(this).attr('type') == 'root')
                    {
                      var node = $(this).attr('p_node');
                      return node;
                    }
              });
             }, function() {
                     //close stuff
  });
  </code></pre>