[JS] while button pressed?

How do you make a loop (while) in javascript which is active while a certain link/button/image is pressed?