Sameer Shaikh
Sameer Shaikh

Reputation: 67

disable table row using jquery

i am trying to disable all the controls inside the table row using jquery, but not being able to do so...below is the my html code

<tr id="trChild2">
                    <td>
                        2
                    </td>
                    <td style="height: 30px;">
                        <%:Html.TextBoxFor(m=>m.childName2) %><%--<br />
                        <%: Html.ValidationMessageFor(m=>m.SpouseName,null,new{@Class="field-validation-message"}) %>--%>
                    </td>
                    <td style="height: 30px; text-align: center;">
                        &nbsp;M<%: Html.RadioButtonFor(m=>m.genderIdChild2,1) %>
                        &nbsp;F<%:Html.RadioButtonFor(m=>m.genderIdChild2,2) %>
                    </td>
                    <td style="height: 30px; text-align: center;">
                        <%:Html.TextBoxFor(m=>m.ageChild2,new{Style="width:30px;",maxlength=3}) %><%--<br />
                        <%:Html.ValidationMessageFor(m=>m.SpouseAge,null,new{@Class="field-validation-message"}) %>--%>
                    </td>
                    <td style="height: 30px; text-align: center;">
                        &nbsp;&nbsp;&nbsp;Married<%: Html.RadioButtonFor(m=>m.maritialStatusChild2,1) %>
                        UnMarried<%:Html.RadioButtonFor(m=>m.maritialStatusChild2,2) %>
                    </td>
</tr>

below is my jquery code, which i have used to disabled all the controls inside the table row.

$("#trChild2").find("input,button,textarea").attr("disabled", true);

please note that the #trChild2 is my table row id

kindly let me know what i am doing wrong...

thanks & regards Sameer shaikh

Upvotes: 0

Views: 6659

Answers (3)

Techie
Techie

Reputation: 45124

There can be few reasons. May be there can be a jQuery conflict in your code. Use the code below to ignore the conflict.

$.noConflict();/jQuery.noConflict();

Then instead of using $, use jQuery word. Read more

Trying adding a (document).ready function. It allows you to execute the functions you want after the DOM has been loaded.

jQuery(document).ready(function($) {
  jQuery("#trChild2").find("input,button,textarea").attr("disabled", true);
});

If you want to know how the (document).ready works Read more here

Hope this helps you to get your work done.

Upvotes: 0

webdeveloper
webdeveloper

Reputation: 17288

Put your code in ready block:

$(function(){
    $("#trChild2").find("input,button,textarea").attr("disabled", true); 
});

Upvotes: 2

STO
STO

Reputation: 10648

Please check http://jsfiddle.net/3QuT4/ it is simple example and it works in the way you specified.

Upvotes: 0

Related Questions