« XUL Reference home
removeItemAt( index )
Return type: element
Removes the child item in the element at the specified index. The method returns the removed item.
<script language="javascript">
function removeSelectedItem(){

    var myListBox = document.getElementById('myListBox');

    if(myListBox.selectedIndex == -1){
        return; // no item selected so return
    }else{
        myListBox.removeItemAt(myListBox.selectedIndex);
    }
}
function removeAllItems(){

    var myListBox = document.getElementById('myListBox');
    var count = myListBox.itemCount;
    while(count-- > 0){
        myListBox.removeItemAt(0);
    }
}
</script>

<button label="Remove selected item" oncommand="removeSelectedItem()"/>
<button label="Remove all items" oncommand="removeAllItems()"/>
<listbox id="myListBox">
  <listitem label="Alpha"/>
  <listitem label="Beta"/>
  <listitem label="Oscar"/>
  <listitem label="Foxtrot"/>
</listbox>

See also