added link to jsfiddle.
wrap init logic inside a DOMContentLoaded listener.