Cut a 4-by-4-inch square of bright yellow cardboard. If yellow cardboard isn't available, glue bright yellow construction paper to a piece of sturdy cardboard.
Smear a thick layer of petroleum jelly onto the cardboard sheet, using a small spoon. Cover all portions of one side of the cardboard with the jelly.
Set two to four cardboard traps around the affected houseplants. Place one or two of the traps directly on top of the soil in the pot if there is room.
Check the trap daily and discard it when it becomes coated in gnats. Replace each discarded trap with a new trap.
Keep the traps around the plant and continue to rotate new ones in until no more dead gnats are found stuck to the petroleum jelly. This may take several weeks, depending on the severity of the infestation.