Search code examples
javascriptphpjqueryhtmluncaught-exception

How to load a j query inside the appending html tag


$(document).ready(function() {
  setInterval(function() {
    $("#appointment").html('<a class="btn btn-default dropdown-toggle" data-toggle="dropdown" href="#"><i class="fa fa-bell fa-fw"></i><span class="badge"  prettydate data-date-format="YYYY.M.D h:m:s"><?php echo $date;?></span> <i class="fa fa-caret-down"></i></a>');
  }, 1000);
});

I have used prettydates jquery to show the time in a way that it shows how long ago.. (https://fengyuanchen.github.io/prettydate/)

but I have inserted this html tag after loading the full script so i couldn't get the actual(long ago..) part I actually get the date that is printed by the php. It doesn't change.. how can i make it?


Solution

  • Prettydate has an autoUpdate option designed for what you're doing.

    $(".prettydate-auto-update").prettydate({ autoUpdate: true, duration: 1000 });
    

    Here's a js fiddle as an example.

    https://jsfiddle.net/y7bu12kk/2/