A new method of preparing CdS nanoparticles inside MCM-41 is described. This method makes uses of the unique interfacial properties of selectively functionalized ordered mesoporous materials to deliver cadmium ions inside the mesopores of MCM-41 via an ion-exchange reaction, thereby minimizing uncontrolled precipitation reactions of cadmium ions outside the mesopores. The general methodology can also be used to prepare other sulfide, telluride, and oxide nanoparticles.