Want to save a few lines of code but dont know how to do it

Want to save a few lines of code but dont know how to do it

Hi all,

I am using JQuery 1.42 to write a simple popup table to show some information to users when they
move the mouse over a string of sentence.

Here is the code I copied from a web site:
  1. <script>
  2.     $(document).ready(function(){   
  3.         $("#link").mouseover(function(){
  4.             $("#popup_menu").show();
  5.             return false;
  6.         });
  7.         $("#popup_menu").mouseout(function(){
  8.             $(this).hide();
  9.             return false;
  10.         });       
  11.     });             
  12. </script>
<a href="#" id="link">Main Message</a>

The code definitely works, but the script is confined to one link only.
What if there are tens of links like these:
<a href="#" id="link2">Message 2</a>
<a href="#" id="link3">Message 3</a>
...<a href="#" id="link100">Message 100</a>
In that case I have to write many scripts accordingly:

  1. <script>
  2.     $(document).ready(function(){   
  3.         $("#link2").mouseover(function(){
  4.             $("#popup_menu").show();
  5.             return false;
  6.         });
  7.         $("#popup_menu").mouseout(function(){
  8.             $(this).hide();
  9.             return false;
  10.         });       
  11.     });             
  12. </script>

  1. <script>
  2.     $(document).ready(function(){   
  3.         $("#link3").mouseover(function(){
  4.             $("#popup_menu").show();
  5.             return false;
  6.         });
  7.         $("#popup_menu").mouseout(function(){
  8.             $(this).hide();
  9.             return false;
  10.         });       
  11.     });             
  12. </script>
In Javascript I would simply write a function like this to save the code:
function(whichLinks){
    $(document).ready(function(){   
        $("#whichLink").mouseover(function(){
            $("#popup_menu").show();
            return false;
        });
        $("#popup_menu").mouseout(function(){
            $(this).hide();
            return false;
        });       
    });       

}

But I don't know how to do this in JQuery.
Could you help me modify the code please?

Thank you