move jQuery append out of function