Noob question about scope with .each

Noob question about scope with .each

I've been scouring the forums and online searches, but I can't find an example that helps me so hopefully someone here can.  I'm building a list using the results from a PHP call using $.get.  Inside the callback for $.get I use a .each call to iterate over the results.  Within the callback for the .each call I am building each line item for the list of results and I want each result to have an onclick handler that will call a javascript function to select the line item.  My problem, I think, is scope.  Within each iteration of the .each loop, "this" refers to the resulting object, so when the user clicks the line, nothing happens (function not called).  When building the list, how can I tell it that when you click this item, call a function that is outside the scope of the .each loop?

Here's an example (sorry for the formatting...the "insert code" button isn't working):


<script>

  $(document).ready(function()
  {
    $.get(someScriptPath, function(results)
    {
      $(results).find('someKey').each(function()
      {
        //build a sting to append to the DOM
        //normally, I'd be doing something with each result....this is just a dumb example

        var newString = "<li><a href='javascript:myFunction()'>FOO</a></li>";

        $("#myList").append(newString);
      });
    }, "xml");
  }


  function myFunction()
  {
    //do something on click
  }
</script>