#1
  1. A Change of Season
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,528
    Rep Power
    221

    From Javascript to html element


    Hello;

    I want some help with a piece of Javascript.

    I use https://momentjs.com/ library (really nice by the way), to view countdown timer on screen.

    It works sweet. Here is my code:

    Code:
    var timezone = "Australia/Sydney";
    var $clock = $('#clock');
    $clock.on('update.countdown', function(event) {
    $(this).html(event.strftime('%-D days %-H Hours %-M Minutes & %S Seconds'));
    
    function updateCountdown() 
          {
            var date = moment.tz("2019-05-25 00:15", "YYYY-MM-DD HH:mm", timezone);
            $clock.countdown(date.toDate());
          }
       updateCountdown();
    It shows the correct countdown timer 371 days 18 Hours 23 Minutes & 57 Seconds inside this div:

    Code:
    <div id="clock"></div>
    What I need to do and totally suck at, is to show the days, hours, minutes and seconds in html like this:

    Code:
    <span class="days">6</span>
    <span class="hours">18</span>
    <span class="minutes">23</span>
    <span class="seconds">57</span>
    Thanks
  2. #2
  3. A Change of Season
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,528
    Rep Power
    221
    I actually thought of this, but I still wanna get approval it's decent:
    Code:
    $(".days").text(event.strftime("%-D"));
        $(".hours").text(event.strftime("%-H"));
        $(".minutes").text(event.strftime("%-M"));
        $(".seconds").text(event.strftime("%-S"));

IMN logo majestic logo threadwatch logo seochat tools logo