title: Get the id of previous sibling anchor element in javascript
body: <p><strong>Solved :</strong> to get the id of the previous element, use <code>previousElementSibling.id</code> instead of <code>previousSibling.id</code>. Thank you to Xufox and Skyline3000 who quickly provided the solution.</p>
  
  <hr>
  
  <p>Having some breadcrumbs done of anchors elements, I'm trying to get the id of the previous sibling when one breakcrumb is clicked (i.e. the parent category).
  eg. <code>Fruits&gt; Apples&gt; Green apples</code></p>
  
  <p>Unfortunately, my code does not work.</p>
  
  <ul>
  <li><code>alert(this.previousSibling)</code> returns <code>[object Text]</code></li>
  <li><code>alert(this.previousSibling,id)</code> returns <code>id is undefined</code>.</li>
  <li><code>alert(this.previousSibling,getAttribute(\'id\')</code> returns <code>TypeError: this.previousSibling.getAttribute is not a function</code>.</li>
  <li><code>alert(this.previousSibling,attr(\'id\'))</code> returns <code>TypeError: this.previousSibling.attr is not a function</code>.</li>
  </ul>
  
  <p>I assume that the sibling is not correctly reached as I was expecting some Element or Object and not Text.</p>
  
  <p>Here's what the HTML and javascript of two breadcrumbs look like:</p>
  
  <pre><code>&lt;a id="n5_40_64_40" onclick="javascript:
      var tree=jQuery('#tree').dynatree('getTree');
      if (!tree.activateKey('40')) {
        var parent=0;
        if (1) {
         parent=this.previousSibling.id.split(/[_]+/).pop();
        }
      }
      return false;" href=""&gt;Apples&lt;/a&gt;
  &gt;
  &lt;a id="n5_40_64_64" onclick="javascript:
      var tree=jQuery('#tree').dynatree('getTree');
      if (!tree.activateKey('64')) {
        var parent=0;
        if (2) {
         parent=this.previousSibling.id.split(/[_]+/).pop();
        }
      }
      return false;" href=""&gt;Green apples&lt;/a&gt;
  </code></pre>