user1592980 user1592980 - 1 year ago 73
Javascript Question

Can't remove range of options inside multiple select tags

I'm using jQuery and I have a group of select elements saved to servoSelects. Some of them have class "lgServo" and some don't. Of the ones that have that class, I want to remove all the options between index 0 and ~variable~. I don't understand how to do this.


This line of code doesn't work but is it close to what I want?

Answer Source

I don't understand how to do this.

String concatenation:

servoSelects.filter('.lgServo').find('option:gt(0):lt(' + variable = ')');
// --------------------------------------------------^^^^^^^^^^^^^^^^^^^

or possibly slice:

servoSelects.filter('.lgServo').find('option').slice(0, variable).remove();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download