The gel fragment is placed in a dialysis tube that is permeable to fluids but impermeable to molecules at the size of DNA, thus preventing the DNA from passing through the membrane when soaked in TE buffer. An electric field is established around the tubing (in a way similar to gel electrophoresis) long enough so that the DNA is removed from the gel but remains in the tube.  The tube solution can then be pipetted out and will contain the desired DNA with minimal background.