Question: In jQuery, how would I descend as far as possible into the HTML tree?

For simplicity, I only have one path going downward. 

(related but bonus: how do I find the deepest element with multiple downward paths?)

```
<html>  
  <table id="table0">  
    <tr>  
      <td id="cell0">  
        <div class"simple">  I want to change this information </div>  
      </td>
    </tr>  
  </table>  
</html>

```

I want to change the innermost HTML of the cell named **cell0** but I don't necessarily know the names of all the classes inside. Is it possible to select this far without knowing these names?

Thanks much!

Answer: 
With a single path:

```
var elem = $('#table0'),
    next;
while ((next = elem.children(':first')).length > 0)
  elem = next;
// elem now points to the deepest child of table0

```

If I get time, I'll update my answer with the code for multiple paths.
The first thing I would do is run a [depth first search (DFS)](http://en.wikipedia.org/wiki/Depth-first_search) and keep track of what level I was at for each node in the DOM.

In order to save having to perform a full DFS every time you want to change something (assuming you'd like to do it multiple times), you could tag each DOM node with its level in the tree as the search is performed. (Then again, you could maybe do this level tagging during the generation of the table?) Once the search is completed and you've determined the deepest node, keep a reference to that node.

From that point, you should be able to quickly update what node is at the deepest level at any given time.