use jquery for generic function instead of loop