title: JQuery toggle function, JS parameter passing
body: <p>I've made a button with toggle action to display data (show/hide on click).</p>
  
  <p>It all works as expected, data is hidden at start because of <code>display: none</code> and then whenever I click on it once it appears, and second click hides the data.</p>
  
  <p><strong>Goal:</strong> I'm trying to make a polymorphic function with argument <code>name</code> that I would pass so that every different <code>id</code> could use the same function, without repeating the same code over and over again. I'd be very grateful if somebody could steer me in the right direction, I think the answer is pretty easy, just can't see it atm.</p>
  
  <p><strong>Problem 1.</strong> When I implemented it the way shown below, it requires on the first attempt 3 mouse clicks, and then 2 to perform the action of <code>show/hide</code>.</p>
  
  <p><strong><em>JS</em></strong></p>
  
  <pre><code>&lt;script&gt;
  function show_panel() {
      $(document).ready(function(){
              $("button").click(function(){
                      $("#add_group").toggle(); // div id
              });
      });
  }
  &lt;/script&gt;
  </code></pre>
  
  <p><strong><em>HTML</em></strong></p>
  
  <pre><code>&lt;button onclick="show_panel()"&gt;Add group&lt;/button&gt;
  &lt;div id="add_group" style="display: none"&gt;
  </code></pre>
  
  <p><em>Note: Code without being wrapped inside a function works as expected (1click for every action):</em></p>
  
  <pre><code>&lt;script&gt;
      $(document).ready(function(){
              $("button").click(function(){
                      $("#add_group").toggle();
              });
      });
  &lt;/script&gt;
  
  &lt;button"&gt;Add group&lt;/button&gt;
  &lt;div id="add_group" style="display: none"&gt;
  </code></pre>
  
  <p><strong>Problem 2.</strong> Passing the <code>id</code> correctly to the function.</p>
  
  <p>According to code from <strong>Problem 1</strong> I've modified the script:</p>
  
  <pre><code>Line 2: function show_panel(name) {
  Line 5: $("#".concat(name)).toggle(); // name is the div id I want to pass
  </code></pre>
  
  <p>I've so far been trying to pass the <code>id</code> without success</p>
  
  <pre><code>&lt;button onclick="show_panel('add_group')"&gt; ...
  &lt;button onclick="show_panel("add_group")"&gt; ...
  &lt;button onclick="show_panel(add_group)"&gt; ...
  </code></pre>
  
  <p>Hope that this is a clear question.</p>