DOM:how to remove select options


remove first option:

function removeFirstOption(selectId)
{
  var select = document.getElementById(selectId);
    select.remove(0);
}

remove last option:

function removeLastOption(selectId)
{
  var select = document.getElementById(selectId);
    select.remove(select.length - 1);
}

remove all options:

function removeAllOptions(selectId)
{
  var select = document.getElementById(selectId);
  while (select.length > 0)
  {
    select.remove(select.length - 1);
  }
}
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • RSS
  • Twitter
  • Yahoo! Bookmarks
  • Yahoo! Buzz
  • BlinkList
  • blogmarks
  • DZone
  • E-mail this story to a friend!
  • LinkaGoGo
  • Live
  • MisterWong
  • MisterWong.DE
  • Reddit
  • StumbleUpon
  • Technorati
  • ThisNext
  • Tumblr

Related posts:

  1. DOM: how to delete table row(s)

One Response to “DOM:how to remove select options”

  1. [...] DOM:how to remove select options By waywalker1 More [...]

Leave a Reply


wp