Core: Throw an error on $("#") rather than returning 0-length collection

Closes gh-1682

Thanks @goob for the issue report!
(cherry picked from commit 80022c81ce4a07a232afd3c580b0977555a2daec)