title: jquery dynamic function
body: <p>I just need the logic and understanding on how I can do this.</p>
  
  <p>The problem:</p>
  
  <p>I have several functions that are very similar but I want to create/call the dynamically</p>
  
  <p>Example:</p>
  
  <pre><code>$(document).ready(function() {         
      function foo() {
          $("#foo_elem").toggle(true).attr('required', true);
          alert('This is foo');
      }
  
      function bar() {
          $("#bar_elem").toggle(true).attr('required', true);
          alert('This is bar');
      }
  });
  </code></pre>
  
  <p>How can I pass in foo/bar to create the function? Pseudo code</p>
  
  <pre><code>$(document).ready(function() { 
      // would pass foo/bar to this?        
      $($x)(function() {
          $("#"+$(this)+"_elem").toggle(true).attr('required', true);
          alert('This is '+$(this));
      });
  });
  </code></pre>