title: Click event fires on one tab but not other tabs
body: <p>I have an loop that generates tabs for each element in the collection. The tabs generate correctly and the content on the tabs generates correctly. Every tab has a DropDownList control with a list of items in it. All seems to be working properly except one thing. The javascript click event for the control on the first tab fires but all other tabs the click event does NOT fire?? </p>
  
  <p>I was thinking each tab would have it's own event handler so that code is part of the loop. However the "name/id" of the control is the same on every tab and I wonder if this is my issue.</p>
  
  <p>Is there some sort of difficulty / problem with each tab having the same "named" control? I thought...perhaps incorrectly...that each tab would have it's own context thus there wouldn't be any issues.</p>
  
  <p>Code for the loop:</p>
  
  <pre><code>foreach (var extbrd in Model.ExtBds)
  {
      tabstrip.Add()
      .Text(extbrd.ExtName)
  
      .ImageUrl("~/.../TabIcon.png")
      .Content(@&lt;text&gt;
                  &lt;div&gt;
                  @Html.Action("Controller", "Action", new { object })
                  &lt;/div&gt;
                 &lt;/text&gt;);
   }    
  </code></pre>
  
  <p>As you can see in the loop the tab code is a partial view. I have snipped out alot of extra code but can post / edit it in if needed. That code is:</p>
  
  <pre><code>....snip
  &lt;script type="text/javascript"&gt;
     $(function() {
         $("#@Html.FieldIdFor(model =&gt; model.ExtFIds)").click(function () 
          {...this code works fine so dropped it....});
     });
  
  &lt;/script&gt;
  ....more snipping....
  &lt;tr&gt;
     &lt;td style="width:400px;"&gt;           
        @Html.DropDownListFor(model =&gt; model.ExtFIds, Model.SelectThreads, new {style = "width:400px;height:400px", @size = 30})
     &lt;/td&gt;
  </code></pre>
  
  <p>So you see the code uses the same name for the control and thus the javascript .click event handler.</p>
  
  <p>Also I think it would be helpful to know that I am using the Telerik mvc tab control object. </p>
  
  <p>Using the F12 debugger I see no errors in the console or similiar....it seems to me that the click event is just not firing on tab 2 and on...?</p>
  
  <p>Any ideas would be greatly appreciated.</p>
  
  <p>Thank You</p>
  
  <hr>
  
  <p>Edit 1 per a suggestion I did this to add a class:</p>
  
  <pre><code>&lt;td&gt;           
     @Html.DropDownListFor(model =&gt; model.ExtFIds, Model.SelectThreads, new {style = "width:400px;height:400px", @size = 30, @Class = "ddlTab_" + Model.ExtFIds.ToString() } )
  &lt;/td&gt;
  </code></pre>
  
  <p>and javascript:</p>
  
  <pre><code>$(".ddlTab_@(Model.ExtFIds)").click(function ()
  </code></pre>
  
  <p>This resulted in every ddl having a uniques class name and a unique event handler but the first tab still only worked???</p>
  
  <hr>
  
  <p>Edit 2</p>
  
  <p>I slightly modified the proposed answer to this:</p>
  
  <pre><code>&lt;div class="Tab"&gt;
     @Html.Action("Controller", "Action", new { object })
  &lt;/div&gt;
  </code></pre>
  
  <p>and the javascrip to this:</p>
  
  <pre><code> $("div.Tab").click(function () 
      {
          alert(this.id);
  </code></pre>
  
  <p>The result was that I did get an alert to pop when I clicked on the ddl...which makes sense because it is in the div which has a handler on it but the alerts were empty. I also got two alerts so it fired the click event twice even though I only clicked one item in the ddl?</p>
  
  <hr>
  
  <p>Edit3</p>
  
  <p>Instead of wrapping the outer div which is the loop of the partial view I changed the div to wrap JUST the ddl creation and added an id like so:</p>
  
  <pre><code>&lt;div class="Tab" id="ddlTab_@(Model.ExtFIds.ToString())"&gt;          
              @Html.DropDownListFor(model =&gt; model.ExtFIds, Model.SelectThreads, new {style = "width:400px;height:400px", @size = 30} )
  &lt;/div&gt;
  </code></pre>
  
  <p>My alert now yields the name of the div clicked. Still fires twice but I can live with that for now.</p>
  
  <p>So now that it is firing I suppose what I have to do is drill down to the child object of the div which would be the ddl...get the selected item and proceed as normal from there.</p>
  
  <hr>
  
  <p>Final Edit--Resolved</p>
  
  <p>So I got it working by using a div wrapped around the ddl but it sure seems to me this is a band-aid / work around...perhaps not though..I just don't know enough to say. For anyone else here is what I ended up doing. </p>
  
  <p>In the razor cshtml I wrapped the ddl in a div as mentioned above in edit 3 and made sure it had a unique id (uniqueness provided by my model ExtFIds).</p>
  
  <pre><code>&lt;div class="Tab" id="ddlTab_@(Model.ExtFIds.ToString())"&gt;          
      @Html.DropDownListFor(model =&gt; model.ExtFIds, Model.ST, new {style = "...", @size = 30, @Class = "ddlTab_" + Model.ExtFIds.ToString() } )
  </code></pre>
  
  <p></p>
  
  <p>In the script portion:</p>
  
  <p>$(function() {
          $("div.Tab").click(function () //so I attach event handler to div instead of ddl
          {
              var id = this.id
              var idLen = id.length;</p>
  
  <pre><code>        id = id.substr(7, idLen);
          //get the div id and then trim off the leading string
  
          //get our raw html string and load it into an object
          var rawModel = $('#HiddenModel_' + id).html();
          //here I access a control on the tab using the id obtained above...
          //of course in the cshtm I concat the model id to the name as seen for the div
  
  
          var jsonModel = jQuery.parseJSON(rawModel) //turn the data into json object
  
          var selectedItem = $('.ddlTab_' + id).val();
           //here I have to drill down to the correct ddl to find the selected item
           //again the model id provides unique name
  
          var matchingObj = getObjects(jsonModel, 'ThreadValue', selectedItem);
          //search through my json object to find matching item.
  
          if(matchingObj.length &gt; 0)
          {
              //update two controls with matched value
              //at this point I think you get the idea...the model id makes for 
              //unique names that can be drilled down to from the wrapping div
              var $FrmDiv = $('#ForumFrame_' + id);
              if ($FrmDiv.length)
              {
                  $FrmDiv.empty();
                  $FrmDiv.append(matchingObj[0].Link);
              }
  
  
              var $prevfram = $('#ForumPreview_' + id);
              if ( $prevfram.length ) {
                  $prevfram.val(matchingObj[0].Description);   
              }
          }
  
      });
  });
  </code></pre>
  
  <p>I welcome any improvements / suggestions / explanations as to this post.</p>