Look at the source code of this very page (it's super simple) or see the same examples on jsFiddle:
Download from Github