Wednesday, July 31, 2013

Access Controls with same id using jquery in ASP.NET MVC


@Html.RadioButton("rdoGp_PriTenant", "rdoGp_PriTenantYes", true)<label>Yes</label> @Html.RadioButton("rdoGp_PriTenant", "rdoGp_PriTenantNo", false)<label>No</label>

Let's say you have two radio buttons with same id and you want to disable them.

when you use 


it selects only the first element with the given ID.

However, when you select by attribute (e.g. id in your case), it returns all matching elements, like so: 

$("[id=rdoGp_PriTenant]").attr('disabled', 'disabled');

Working code using Jquery would be: 


<script src="//"></script> 
 $(document).ready(function () { 
   $("[id=rdoGp_PriTenant]").attr('disabled', 'disabled'); 

No comments:
Write comments
Recommended Posts × +