Fix `$.contains` on browsers that don't support native `contains()`

This fixes `$.contains` and functionality that depends on it on
Firefox 4.0 – 8.0.

Fixes #963