Many times in the anime, many characters explain how and why electric moves have no effect on ground Pokémon and how and why they are weak against grass.
One of the best times they explained this was in this episode: https://www.dailymotion.com/video/x553h9e
Season: Advanced generation series
Episode 007, Tree's a Crowd
https://bulbapedia.bulbagarden.net/wiki/AG007
Go for 21:40 minutes
Brock will explain!!
--
Max ask why Pikachu thunderbolt work normally against Treecko, since Treecko was a grass type and electric moves was weak against grass types. Brock then will explain that the electric move worked normally because it hit Treecko when he was jumping!!
Brock explain that electric moves are weak against grass and have no effect on ground Pokémon because the eletricity flow throught the body of the Pokémon and hit the ground or tree right away, dispersing the energy, them the grass Pokémon take minor damage and the ground Pokémon take no damage!
But when the Pokémon is not on the ground, like hoving or jumping, like in the case of Treecko, the move work normally because the Pokémon is not on the ground, so the energy has not to defuse on it!
--
In the fight against Roxane, Ash waited the right time to hit Geodude with a electric move, when Geodude was hoving.