The occurrence of aragonite in speleothems has commonly been related to high dripwater Mg/Ca ratios, because Mg is known to be a growth inhibitor for calcite. Laboratory aragonite precipitation experiments, however, suggested a more complex array of controlling factors. Here, we present data from Pleistocene to Holocene speleothems collected from both a dolostone and a limestone cave in northern Morocco. These stalagmites exhibit both lateral and stratigraphic calcite-to-aragonite transitions. Aragonite fabrics are well-preserved and represent primary features. In order to shed light on the factors that control alternating calcite and aragonite precipitation, elemental (Mg, Sr, Ba, U, P, Y, Pb, Al, Ti and Th) abundances were measured using LA-ICP-MS, and analysed with Principal Component Analysis. Samples were analyzed at 100–200 μm resolution across stratigraphic and lateral transitions. Carbon and oxygen isotope ratios were analysed at 100 μm resolution covering stratigraphic calcite-to-aragonite transitions. Results show that the precipitation of aragonite was driven by a decrease in effective rainfall, which enhanced prior calcite precipitation. Different geochemical patterns are observed between calcite and aragonite when comparing data from the Grotte de Piste and Grotte Prison de Chien. This may be explained by the increased dripwater Mg/Ca ratio and enhanced prior aragonite precipitation in the dolostone cave versus lower dripwater Mg/Ca ratio and prior calcite precipitation in the limestone cave. A full understanding for the presence of lateral calcite-to-aragonite transitions is not reached. Trace elemental analysis, however, does suggest that different crystallographic parameters (ionic radius, amount of crystal defect sites, adsorption potential) may have a direct effect on the incorporation of Sr, Mg, Ba, Al, Ti, Th and possibly Y and P.