Uncaught TypeError: Can not set property 'innerHTML' of null when closing modal boostrap

0

I have an error generated by console that is Uncaught TypeError: Can not set property 'innerHTML' of null. This error occurs when closing a modal window, which contains a counter that is generated through datetime from the database. Previously this error, was produced when opening the modal, but solve it, putting the tags in the boostrap (which I do not know if it is the right solution, but it worked in that case).

The code generated by the meter and showing the information in the modal is:

<html>
 <body>
  <h5>RETRASADO EN: <p id="demo"></p></h5>
  <hr>
   <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
</div>
 </body>
</html>

<script>

var tiempo = '<?php echo $tiempo;?>';
var splitDate = tiempo.split(" ");
var date = splitDate[0].split("-");
var time = splitDate[1].split(":");
var dd = date[2];
var mm = date[1]-1;
var yyyy = date[0];
var hh = time[0];
var min = time[1];
var ss = time[2];

var countDownDate = new Date(yyyy, mm, dd, hh, min, ss).getTime();

var x = setInterval(function() {

 var now = new Date().getTime();
 var distance = now - countDownDate;
 var days = Math.floor(distance / (1000 * 60 * 60 * 24));
 var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
 var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
 var seconds = Math.floor((distance % (1000 * 60)) / 1000);

 document.getElementById('demo').innerHTML = days + "d " + hours + "h " + minutes + "m " + seconds + "s ";

 if (distance < 0) {

  document.getElementById('demo').innerHTML = days + "d " + hours + "h "
  + minutes + "m " + seconds + "s ";
 }
}, 1000);

The code line that opens the modal is:

return '<a href="#myModal" data-toggle="modal" data-target="#retrasado" class="btn btn-xs btn-rounded btn-danger"><b>ABRE MODAL</b></a>';

The modal opens from a button generated in datatables.

As I mentioned before, this error occurs when closing the modal, when this is open, it does not generate any type of errors. Who has any idea why this may be happening? Greetings to all and many thanks for your help and / or guidance. PS: If some code is missing or more information is needed, I will gladly edit the question if necessary ..

    
asked by maha1982 02.12.2018 в 02:44
source

0 answers