When two objects rub together, electrons can be transferred between them. This transfer of electrons causes a static electric charge to be built up on the surface of the objects. This charge causes the objects to attract each other due to the electrostatic force. The strength of the electrostatic force depends on the amount of charge that was transferred and the distance between the two objects.