Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove options select with a value greater than 0

Tags:

jquery

I would to remove all the options (but the first one with value = 0) from a select with id="myid".

I wouldn't to use empty() and then append().

like image 952
Sefran2 Avatar asked Nov 09 '12 21:11

Sefran2


1 Answers

If it is the first element, use gt and remove

$("#myid option:gt(0)").remove();

use attribute selector

$('#myid option[value!="0"]').remove();

use filter

$('#myid option').filter(
    function () {
        return parseInt(this.value,10) !== 0; 
    }
);
like image 117
epascarello Avatar answered Nov 09 '22 07:11

epascarello