Bind a callback function after Dom is ready.
$(document).ready(function(){
//Code here
});
or
(function($){
$(function(){
//Code here
});
})(jQuery);