destroying fgelinas jquery-ui-timepicker

1.9k Views Asked by At

I am using this time picker.

Problem is, when I navigate to another page while the time picker is shown, it will still be shown on the next screen when it loads. How do I destroy the timepicker?

Have tried the below but to no avail.

tp.timepicker('destroy');
tp.timepicker('remove');
tp = null;
2

There are 2 best solutions below

11
On BEST ANSWER

Here is the working JSFIDDLE HTML:

<input type="text" style="width: 70px;" id="timepicker" value="" />
<input type="button" value="Destroy it !" id="destroy">

JS:

$(document).ready(function(){
    $('#timepicker').timepicker();
    $('#destroy').click(function(){
       $('#timepicker').timepicker('destroy'); 
       $('#timepicker').timepicker('hide');
    });
});
1
On

It is not well documented, but there is a destroy method :

$($elem).timepicker('destroy');

Calling the destroy method should unbind events from the input and remove most of what was instatiated for the timepicker.