Kaur Kaur - 4 months ago 13
Javascript Question

Remove text adjacent to element I'm trying to remove

I need to remove the label "Time:" as well as the time field. I could only remove the field using the following code:

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


How do I remove the time as well?

<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>