To understand how static electricity works with a simple experiment.
A water faucet.
A plastic comb.
Run the comb through your hair thoroughly
Open the tap and let the water flow with minimal force. Do not open the tap too much as the water stream needs to be thin.
Bring the comb close to the water and hold it around 1-2 inches away from the water and 3-4 inches below the tap.
Observe the stream of water bending towards the comb
When two objects are rubbed against each other, electrical charge is accumulated. Before rubbing, the objects would have been electrically neutral, that is, they would have had equal number of positive and negative charges. However when they are rubbed together, depending on the nature of the objects, charges of one kind will get transferred to one of the objects so that one object will have a net positive charge and the other will have a negative charge. When you rub the comb through your hair, the comb accumulates one kind of charge. This charge attracts the stream of water and makes it bend towards the comb.