find next element with conditions
<p>Hierarchical tree:  </p>

<pre><code>  mouse (depth:0, sequence:0)
    *   organ system (depth:1, sequence:1)
        o   visceral organ (depth:2, sequence:2)
              urinary system (depth:3, sequence:3)
              mesentery (depth:4, sequence:4)
                  *   rest of mesentery (depth:5, sequence:5)
                  *   urogenital mesentery (depth:5, sequence:6)
              metanephros (depth:4, sequence:7)
                  *   renal capsule (depth:5, sequence:8)
                  *   nephrogenic zone (depth:5, sequence:9)
</code></pre>

<p>I have the following code which should retrieve the name of the the FIRST next node after the selected node, which has the same depth as the selected node and the sequence values should be greater than selected_node_sequence :</p>

<pre><code>/** node id has the same value as node_depth **/

  var selected_node_depth = parseInt($j(element).attr('APO_DEPTH'));
  var selected_node_sequence = parseInt($j(element).attr('APO_SEQUENCE'));

  var first_next_node_with_same_depth = $j("#"+selected_node_depth).next().attr("name"); [where first_next_node_with_same_depth sequence value &gt; selected_node_sequence]
</code></pre>

<p>For example, if 'selected_node' = mesentery, the 'first_next_node_with_same_depth' should be metanephros</p>

<p>Any suggestion on how to do that is most appreciated</p>
