title: Jquery each inside onclick event
body: <p>Razor/HTML (many of these):</p>
  
  <pre><code>&lt;div class="directory-item" id="@item_id" name="@item_name" style="padding-left: @(indent_level)px;  display: @(display)"&gt;
     &lt;i class="fa @icon_type"&gt;&lt;/i&gt;
     @item.ItemName (id: @item_id, name: @item_name, level: @item.Level)
     &lt;i class="fa  fa-angle-right float-right"&gt;&lt;/i&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>$(".directory-item").click(function () {
      $('div[name*=' + this.id + ']').each(function () {
          if (this.attr('display') == "none") {
              this.show();
          } else {
              this.hide();
          }
      });
  });
  </code></pre>
  
  <p>Basic question: how do you put an "each" inside a "click" event and reference the "each" item (each time it accesses an element) with "this"? Maybe I shouldn't be using an each statement but something else?</p>