Well some electricity is created by renewable resources such as wind and solar so in those cases the electric cars are good for the environment and a lot better than gasoline or diesel powered vehicles.
But on the other hand just like you said if the cars use electricity that is generated by using fossil fuels then it's not really a green or environmentally friendly car.
But then again the electricity would be generated anyway and has to go somewhere and it might as well go in the car.