With jQuery 1.6+ (up to edge), this works fine:
Check to make sure that jQuery is loaded before this code appears in the html. Also make sure you are not loading jQuery in noConflict mode, as this will break the use of the $.
If this still fails for you, use the Chrome/Firefox inspector to view any console errors.
If you see an error like:
Uncaught ReferenceError: $ is not defined
One of the two above issues is at fault.