Antifungal medications work by targeting the fungal cell wall, cell membrane, or other fungal-specific enzymes, and disrupting the fungal growth and replication. Some antifungal medications also interfere with the fungal cell's ability to produce ergosterol, which is an essential component of the cell membrane. The choice of antifungal medication depends on the type of fungal infection, the severity of the infection, and the patient's medical history and other factors.