Home > Back-end >  Add a class on dynamic element
Add a class on dynamic element

Time:05-19

I use a countdown DIV that adds a class 'timeisover' to itself when it reaches 00:00:00 and I just want to add a class to his parent when it happens.

<div >
    <div >
        <!-- countdown elements here -->
    </div>
</div>

I tried this but it doesn't work.

$('.countdown').on('change', function() {
    if($(this).hasClass('timeisover') {
        $('.parent-countdown').addClass('disable-countdown');
    )
});

So I guess I need an "event listener" which works live and checks permanently if the element receives this class? I usually use .on with click event but for this, I'm not sure how to proceed :/ So any help would be much appreciate :)

CodePudding user response:

The HurryTimer documentation says it has a "hurryt:finished" EventName:

hurryt:finished: Fires after timer has reached zero.

$('.countdown').on('hurryt:finished', function(event, campaign){

  $(this).closest('.parent-countdown').addClass('disable-countdown');

});
  • Related