« XUL Reference
currentIndex
Type: integer

Set to the row index of the tree caret in the tree. For trees with focus, the caret's position is indicated by the focus ring, but unfocused trees won't show  a focus ring, naturally. For unfocused trees, the (undrawn) caret's position can still be obtained by this property. If the caret isn't present for any row (for example, because the tree has never been focused), the value will be -1.

You cannot rely on this property to change or determine a tree selection, except for trees with seltype="single". (All trees have seltype="multiple" by default.) To reliably change or determine a selection, instead use the nsITreeSelection interface methods available via tree.view.selection.

Example

// One way of retrieving the text of a cell.
<script language ="javascript">
function treeRowClicked(){
    var tree = document.getElementById("my-tree");
    var selection = tree.view.selection;
    var cellText = tree.view.getCellText(tree.currentIndex, tree.columns.getColumnAt(0));
    alert(cellText);
}
</script>

<tree id="my-tree" seltype="single" onselect="treeRowClicked()">
  <treecols>
    <treecol label="Title" flex="1"/><treecol label="URL" flex="1"/>
  </treecols>
  <treechildren>
    <treeitem>
      <treerow>
        <treecell label="joe@somewhere.com"/>
        <treecell label="Top secret plans"/>
      </treerow>
    </treeitem>
    <treeitem>
      <treerow>
        <treecell label="mel@whereever.com"/>
        <treecell label="Let's do lunch"/>
      </treerow>
    </treeitem>
  </treechildren>
</tree>

See also