The typical wall switch used to control light is one of the simplest of electrical components. The most basic type is single-pole, which means it controls only one circuit; and single-throw, which means you can only turn it on or off. Double-pole switches are found in three-way configurations, when two switches power one light; and dimmer switches have more than one setting, or throw. Not much can go wrong inside a switch, and if it does, you usually can't take it apart. Most switch problems are caused by defective wiring.
Turn off the breaker that controls the switch. If you're not sure which breaker this is, then test the switch terminals with a voltage tester. Unscrew the switch cover and remove it, then turn the switch on. Touch one lead from a voltage tester to one of the terminals on the switch and the other to the electrical box, if it is metal, or to the ground screw, and verify that the tester lights up. Turn off the breakers in succession until the light goes off.
Unscrew the switch from the electrical box and pry it off with a slot screwdriver. Examine the wires connected to the terminals, and replace any that are loose or have slipped off. Loosen the terminal screw, wrap the wire clockwise around the terminal, and tighten the screw.
Re-connect frayed wires inside the electrical box. Cut out the frayed section with wire cutters, then strip the ends of the wires with a wire striper. Twist the wires together clockwise with pliers, then screw on a wire cap.
Unscrew the wire cap covering the white wires in the box and verify that none have worked themselves loose. Twist them back together with pliers, and replace the wire cap, screwing it clockwise to ensure that the wires tighten together.
Replace the switch if you can find no problems with the wiring, and it appears to be defective. A short circuit or other overload may have melted one of the terminals, or the toggle may have broken. Switches are inexpensive and easy to replace.
Remove the wires from the switch terminals and discard the old switch. Wind the wires clockwise around the corresponding terminals on a new switch and tighten the screws. If you are replacing a three-way switch, be sure the red wire is connected to the common terminal, which is coloured differently than the other two.
Push the wires back into the box with the handle of your screwdriver, then screw the switch onto the electrical box. If you are installing a replacement switch, use the new screws supplied with it. Place the cover plate over the switch and screw it on, then turn the power back on and test the repair.
Dimmer switches have a rheostat that is more likely to malfunction than the toggle on a single-throw switch. While you can probably repair the rheostat, it is easier and safer to replace the dimmer.
Do not remove the switch from the box without turning off the power. You can get a serious shock if you touch either terminal when it is live.