jQuery select list removes all options

Richbits picture Richbits · Jul 9, 2009 · Viewed 88.3k times · Source

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 the following:

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

But this seems to have no effect.

Part of my problem is that I am using Firebug to debug the JavaScript, but the debugger does not break at the breakpoint, so I cannot see what is going on. Should it break when the JavaScript is within the <head> of my HTML file?

Answer

David Hedlund picture David Hedlund · Jul 9, 2009

this would do:

$('#selectId').html('');