I would store `$(document)` in some variable outside of the function; you potentially look this up a few times.