[Javascript] deleting all options
Andrew Crawford
javascript at evermore.com
Wed Feb 1 12:53:40 CST 2006
It works in Firefox, Opera, and Safari, too.
I'm curious whether there is a good reason not to do it this way
(setting length to 0).
Andrew Crawford
James Conley wrote:
> Oddly enough this works in IE - does it work in other browsers as well?
> Normally .length is read-only for arrays and such.
>
>
> james c
>
>
>
> ------------------------------------------------------------------------
> *From:* javascript-bounces at LaTech.edu
> [mailto:javascript-bounces at LaTech.edu] *On Behalf Of *Peter Brunone
> *Sent:* Wednesday, February 01, 2006 10:53 AM
> *To:* javascript at LaTech.edu
> *Subject:* Re: [Javascript] deleting all options
>
> Can you still set options.length = 0?
>
> Also, innerHTML = "" comes to mind (this might possibly be fastest,
> though not supported by earlier browsers)...
>
> Peter
>
> *From*: "Nick Fitzsimons" nick at nickfitz.co.uk <mailto:nick at nickfitz.co.uk>
>
>> i dynamically fill a .
>> when i do it twice the first created options still are in the new select.
>>
>> now i need ans easy function to clear the
> you can use
>
> // get reference to element
> var element = document.getElementById("mySelect");
> // remove all children of element
> while (element.firstChild) {
> element.removeChild(element.firstChild);
> }
>
> As you presumably already have a variable reference to the select, adjust
> accordingly.
>
> The while loop there is a general purpose way of removing all the child
> nodes of any element, so depending on your needs, you may find it useful
> to move it into a function.
>
> HTH,
>
> Nick.
> --
> Nick Fitzsimons
> http://www.nickfitz.co.uk/
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
More information about the Javascript
mailing list