How can I attach a function without any event to the small
tag element? Basically I want the function to invoke just after the document is ready.
Pug:
each value, index in user.submissions
small(data-end=value.endTime) Status
Javascript:
function() {
const element = $(this);
const endTime = element.data('end');
const currentTime = new Date();
if (Number(endTime) > Number(currentTime)) {
element.html('Running');
}
else {
element.html('Closed');
}
};
I have tried the following code. But that causes all the small tags having the same text. Whether I want the tag to have different text depending on its data attribute value.
$(document).ready(function(){
function() {
const element = $('.small');
const endTime = element.data('end');
const currentTime = new Date();
if (Number(endTime) > Number(currentTime)) {
element.html('Running');
}
else {
element.html('Closed');
}
};