Kaur Kaur - 4 months ago 19
jQuery Question

jquery to remove label

I need to remove the label "Time:" and time field. i could only remove the field. I need help removing the label "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>

Answer

Just remove parent of his parent. Like this:

$('#fieldIncidentTime').parent().parent().remove();
<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>