Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
Hi,

Any one can help me how to disabled HTML using JavaScript,jQuery below is my code.

JavaScript
<script type="text/javascript">
			$(document).ready(function () {
			$(".statuscheck").attr('disabled', "disabled");
            document.getElementsByClassName("statuscheck").disabled = false;
		});

ASP.NET
<table class="table table-bordered">
	<tr class="statuscheck">
		<td>
			<asp:RadioButtonList ID="rbtnRegister" runat="server" CssClass="register" RepeatDirection="Horizontal">
				<asp:ListItem Value="3" Text="Register By Company"></asp:ListItem>
				<asp:ListItem Value="4" Text="Register By Tenent"></asp:ListItem>
			</asp:RadioButtonList>
		</td>
		<td>
			<div class="input-group" style="float: left;">
				<asp:TextBox ID="txtStatus2Date" runat="server" CssClass="form-control"></asp:TextBox>
			</div>
		</td>
		<td style="text-align: center;">
			<asp:Button ID="btnStatus2" runat="server" CssClass="btn btn-primary" Text="Save" OnClick="btnStatus2_Click"></asp:Button>
		</td>
	</tr>
 </table>
Posted
Updated 23-Jun-15 21:25pm
v3

1 solution

The disabled attribute does not exist on a table row. You have to apply it on its inner input elements. Also, the jQuery documentation[^] recommends to use .prop() instead of .attr() for DOM properties such as disabled.

So, to disable/enable all input elements in a row, try this:
JavaScript
// to disable
$("tr.statuscheck input, tr.statuscheck select, tr.statuscheck textarea").prop('disabled', true);
// to enable
$("tr.statuscheck input, tr.statuscheck select, tr.statuscheck textarea").prop('disabled', false);

The above code lines disable/enable all input, select and textarea elements inside a tr tag with class statuscheck.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900