check this function and apply it.

$(function(){
// your code goes here
});