Wrapped the function in jQuery function, which runs when the DOM is loaded..