[Javascript] deleting all options

Shawn Milo Shawn at Milochik.com
Wed Feb 1 12:58:12 CST 2006


Here's how I do it:

         while (drpBox.length){
            drpBox.remove(0);
         }

Milo

On 2/1/06, Andrew Crawford <javascript at evermore.com> wrote:
>
> 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
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20060201/ad29f2fa/attachment.htm>


More information about the Javascript mailing list