document ready

Code below can run if all element from html are load. 
I spent some time to figure out that the reason that script not working, if is situated before catching element.