Trolleys, also known as electrical cars or street cars, are an American invention of the 19th century. Trolleys ran on tracks driven by an electric motor but earlier forms of them either depended on more inefficient and expensive storage batteries, or were horse-drawn as can be seen in the first image. 

 This was a convenient mode of transportation because trolleys traveled in set schedules and routes, and were an option for travel to those who could not afford to own a carriage. As the end of the 19th century approached, a transition towards electrical power in transportation occured as depending on animals for transport required a lot of maintenance and waste. According to Connecticut's Department of Transportation website, in 1890 there were four and a half times more miles of horse-car lines than electric lines; by 1894, the numbers were reversed, with electric mileage exceeding horse-car mileage by a factor of five and a half. Consequently, trolleys largely replaced animal-drawn modes of transportation at a fast rate especially between 1902-1917. 

Fun fact: The first trolley was invented in Vermont by Thomas Davenport, a blacksmith, and was battery-powered.