views:

1179

answers:

4

I have a <select> list which has been populated with several options, but want to remove those options to start again.

I am using Jquery, and have tried:

$("#selectId").length = 0;

but this seems to have no effect.

Part of my problem is that I am using firebug to debug, but the code does not break at the breakpoint, so I cannot see what is going on. Should it break when the Javascript is within the of my Html file?

+2  A: 

this would do:

$('#selectId').html('');
David Hedlund
Thanks, worked a treat..
Richbits
A: 

If without jquery:

javascript SELECT remove()

lance
+2  A: 

Just $("#selectId option").remove(); works too.

AKX
Thanks yes, works fine too.
Richbits
A: 
$("#selectId").options.length = 0;

That won't actually work as written because it's using a jQuery selector. It'd work if you used a straight DOM getElementById on the select list, though. Either AKX's or d.'s responses will set you right.

RwL
thanks, yes you are right, though tried it first..
Richbits