How to use jQuery with Drupal

Putting this here for my own reference and as a reminder. Usually when writing jQuery you'd wrap all your code in a $(document).ready() function, but apparently that isn't "best practices" for Drupal. I can't really explain why very well, just what I've learned.

Drupal7

(function ($) {
  Drupal.behaviors.play = {};
  Drupal.behaviors.play.attach = function(context) {
    $cool jQuery stuff here;
  }
})(jQuery);

Drupal6

(function($){
  Drupal.behaviors.play = function(context){
    $cool jQuery stuff here;
  }
})(jQuery);

Take note that "play" is just an arbitrary name we can make up. You can use anything there, but it's best to use something that includes the name of your theme or module along with what your code is doing, so maybe you'd use bartikHideBlocks or something like that.

I couldn't find this information very easily on Drupal.org so I'm putting it here for my own sanity and in case anyone else could use it. Enjoy!