How to get jquery working on Drupal 7 - for Newbies I have been reading many tutorials online on how to get jquery working on drupal 7.
Although there are many lines of code and examples, what i cannot find is what piece of code to put where (maybe it is obvious for most of the developers)

So, what I do is 

1)I create a new custom block

2)Over there from drupal UI, I write my code

(function ($) {

  $(document).ready(function(){

    // jquery here

  });
})(jQuery);


3)I display the block, but the jquery is not loaded.

I am reading that I should be putting this code in template files , theme files, css files, info files and I do not know whatelse! 

It is not clear to me in which file exactly and in which path I have to put the above code to work properly ?

Any advice?

Many thanks!
A couple of things here:


If you can avoid entering javascript and PHP into the site via the UI it will possibly save you troubles down the line. If you have no alternatives it is ok but here are some reasons why it is not a great idea: https://drupal.stackexchange.com/a/2512/10729 (note that that is aimed at PHP, not js but most of the points still stand for js). The examples module has an example of creating custom blocks.
For attaching js, if you want it on all pages you can add it to your theme's info file. If you only want it in some places though, best to use drupal_add_js() so it is only on pages it needs to be. For attaching js behaviour to forms you can also use #attached attribute on your form items.
If you use $(document).ready(), it will fire your javascript when the page loads, however if the page is updated via ajax then your javascript will not fire again, so new markup won't be affected by whatever your javascript is. To handle these cases you should use drupal behaviors instead of document ready.


For example:

(function ($) {
  Drupal.behaviors.yourBehaviorName = {
    attach: function (context, settings) {
      // Do your thing here.
    }
  };
})(jQuery);


I recommend reading these pages:
Managing JavaScript in Drupal 7
Working with JavaScript and jQuery