how delete all options except second in javascript

Posted by Syom on Stack Overflow See other posts from Stack Overflow or by Syom
Published on 2010-05-17T16:32:08Z Indexed on 2010/05/17 16:40 UTC
Read the original article Hit count: 171

Filed under:

i have a select tag, with some options

<select id="sel">
     <option>text1</option>
     <option>text2</option>
     <option>text3</option>
     <option>text4</option>
</select>

i want to delete all options except second, i.e i want to get

<select id="sel">
     <option>text2</option>
</select>

i think it must looks something like this

document.getElementById('sel').options.length= 0;

but it deletes all list, so could you help me.


thanks

© Stack Overflow or respective owner

Related posts about JavaScript