删除我想要删除的元素旁边的文本

时间:2016-08-10 00:13:02

标签: javascript jquery

我需要删除标签“Time:”以及时间字段。我只能使用以下代码删除该字段:

$('#fieldIncidentTime').remove();

我如何删除时间?

<tr>
   <td><label style="white-space:nowrap;">Incident Date</label></td>
   <td colspan="3" width="85%">
      <div style="float: left;">
         <div id="wwgrp_myForm_incidentDate" class="wwgrp">
            <div id="wwctrl_myForm_incidentDate" class="wwctrl">
               <b class="dpWrapper"><input placeholder="MM/DD/YYYY" name="incidentDate" size="12" value="08/09/2016" id="myForm_incidentDate" class="psDateWidget unvalidated hasDatepicker" type="text"><button tabindex="-1" aria-hidden="true" class="ui-datepicker-trigger" type="button"></button></b>
            </div>
         </div>
      </div>
      <div style="float: left; padding: 0px 0px 0px 10px;">
         Time:                                <span class="timeEntry_wrap"><input id="fieldIncidentTime" name="incidentTime" value="04:35 PM" size="10" class="timeEntry hasTimeEntry" type="text"></span>
      </div>
   </td>
</tr>

1 个答案:

答案 0 :(得分:1)

只需删除其父级的父级即可。像这样:

&#13;
&#13;
$('#fieldIncidentTime').parent().parent().remove();
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<tr>
   <td><label style="white-space:nowrap;">Incident Date</label></td>
   <td colspan="3" width="85%">
      <div style="float: left;">
         <div id="wwgrp_myForm_incidentDate" class="wwgrp">
            <div id="wwctrl_myForm_incidentDate" class="wwctrl">
               <b class="dpWrapper"><input placeholder="MM/DD/YYYY" name="incidentDate" size="12" value="08/09/2016" id="myForm_incidentDate" class="psDateWidget unvalidated hasDatepicker" type="text"><button tabindex="-1" aria-hidden="true" class="ui-datepicker-trigger" type="button"></button></b>
            </div>
         </div>
      </div>
      <div style="float: left; padding: 0px 0px 0px 10px;">
         Time:                                <span class="timeEntry_wrap"><input id="fieldIncidentTime" name="incidentTime" value="04:35 PM" size="10" class="timeEntry hasTimeEntry" type="text"></span>
      </div>
   </td>
</tr>
&#13;
&#13;
&#13;