I need to make that when timer ends I get "Not active" message instead of "Active". The timer and code seems to work until this $('.clock').eq().countdown(inputDate)
after this code, the function not working, no console.log's showing when checking. The same function works on one object but when it comes to foreach loop it doesnt work. This is my html line which should replace:
<td><span class="timeProduct label label-success"></span>
This is my ajax
$(document).ready(function() {
var inputDate = new Date($('#count').text());
var timeProduct = $(".timeProduct");
timeProduct.html('Aktyvus');
inputDate.setDate(inputDate.getDate() + 7);
$(".clock").countdown(inputDate, function(event) {
$(this).text(
event.strftime('%D dienos %Hh %Mmin %Ssek')
);
$('.clock').eq().countdown(inputDate)
.on('finish.countdown', function(event) {
var timeProduct = $(".timeProduct");
timeProduct.removeClass("label label-success");
timeProduct.addClass('label label-danger');
timeProduct.html("Pasibaigė");
});
});
});
EDIT
This is my HTML with foreach loop
@foreach($bids as $b)
<tr>
<td><img style="height: 50px" src="{{$b->product->img_1}}">
<strong><a href="/preke/{{$b->product->id}}/{{$b->product->slug}}">{{$b->product->title}}</a></strong>
</td>
<td>{{number_format($b->product->price, 2)}} EUR</td>
<td>{{$b->created_at}}</td>
<td><span id="count">{{$b->product->created_at}}</span></td>
<td><span class="clock"></span></td> // This is where timer appears
<td><a style="font-size: 11px" href="/unmark-auction/{{$b->id}}" class="unCheck btn btn-danger"><i class="glyphicon glyphicon-remove"></i> Nebesekti</a></td>
<td><span class="timeProduct label label-success"></span>
</td>
</tr>
@endforeach
And this is updated AJAX
$(document).ready(function() {
var inputDate = new Date($('#count').text());
var timeProduct = $(".timeProduct");
timeProduct.html('Aktyvus');
inputDate.setDate(inputDate.getDate() + 7);
$(".clock").countdown(inputDate, function(event) {
$(this).text(
event.strftime('%D dienos %Hh %Mmin %Ssek')
);
var index = $(".clock").index(this);
$('.clock').eq(index).countdown(inputDate)
.on('finish.countdown', function(event) {
var timeProduct = $(".timeProduct");
timeProduct.removeClass("label label-success");
timeProduct.addClass('label label-danger');
timeProduct.html("Pasibaigė");
});
});
});