What would happen if we threw the sparkler into the water? Would it keep burning under water.
Most likely, not. Water is an effective coolant, so a wet sparkler wouldn't be able to propagate a burn front. Pyrotechnic compositions often severely degrade in a wet air (some might self-ignite and some might loose the ability to burn).
Are children's sparklers based on a magnesium reaction?
The most common sparkler composition I'm aware about is
- fine $\ce{Al}$ powder as a fuel,
- $\ce{KNO3}$ as an oxidizer
- dextrin or other combustible binder
- Iron coarse powder for orange-ish sparks.
$\ce{Ti}$, $\ce{Al}$ or $\ce{Sb2S3}$ in coarse powder can be used for producing white sparks. Charcoal powder or potassium poly-sulfides can produce redder sparks. To my knowledge, there is no way to produce purple, blue or green sparks.
Exact composition is a delicate balance between gases produces (so sparks were thrown away at meaningful distance) stability and temperature of burn, amount and color of sparks produced, safety and cost.
Please, note. While a common sparkler cannot burn in water, a big slag with same composition and water-proof coating certainly can. But you don't want to be nearby when it happens. Like, at all. An example with a much tamer fuel here:
https://www.youtube.com/watch?v=czwBWB5u6Hg
Also, magnesium is usually avoided in pyrotechnic compositions in favor of aluminum. Magnesium usually produces a lot of thick, white smoke and is more sensitive when stored in real conditions. If aluminum doesn't burn good enough, $\ce{Mg/Al}$ alloy might be used.