在jquery中删除multilevel div中所有文本框的css类

时间:2014-10-08 18:08:56

标签: jquery

我想删除第3级div中所有文本框的特定css类。

<div class="panel panel-default" id="pnlChangeLoginInfo">
                        <div class="panel-heading">Change Login Information</div>
                        <div class="panel-body">
                            <div class="row">&nbsp;</div>
                            <div class="row">
                                <div class="col-md-5">Current Password:</div>
                                <div class="col-md-7"><input class="form-control" id="txtCurPassword" name="txtCurPassword" type="password" />
                                <input class="form-control" id="hidCurPassword" name="Contact_Model.Password" type="hidden" value="irecadmin01" /></div>
                            </div>
                            <div class="row">&nbsp;</div>
                            <div class="row">
                                <div class="col-md-5">New Password:</div>
                                <div class="col-md-7"><input class="form-control" id="txtNewPassword" name="txtNewPassword" type="password" /></div>
                            </div>
                            <div class="row">&nbsp;</div>
                            <div class="row">
                                <div class="col-md-5">Repeat Password:</div>
                                <div class="col-md-7"><input class="form-control" id="txtRepPassword" name="txtRepPassword" type="password" /></div>
                            </div>
                            <div class="row">&nbsp;</div>
                            <div class="row">
                                <div class="col-md-5">Login Email Address:</div>
                                <div class="col-md-7"><input class="form-control" id="txtLoginEmail" name="Contact_Model.EmailAddress" type="text" value="william.robinson@irec.idaho.gov" /></div>
                            </div>
                            <div class="row">&nbsp;</div>

                        </div>
                    </div>

在这个html中如何删除css类&#34; form-control&#34;所有文本框基于div id&#34; pnlChangeLoginInfo&#34;

1 个答案:

答案 0 :(得分:1)

$('#pnlChangeLoginInfo > div > div > input.form-control').removeClass('form-control');

请注意,此示例非常准确地匹配距离input.form-control元素正好 3级的#pnlChangeLoginInfo个元素。但是,我在其他级别上没有看到符合input.form-control条件的任何其他元素,因此您可能会发现以下内容同样有效:

$('#pnlChangeLoginInfo input.form-control').removeClass('form-control');

第二个优点是它将来会对次要DOM更新更具弹性。