I have a code in helper in meteorjs
Template.tickets.helpers({
priorityClassColour(priority) {
setTimeout(() => {
$(".Low").css('background-color', 'red');
return 'Low'
});
}
})
This works fine without any error but when I move the code of jquery css outside settimeout, the style is not applied to css. When I run $(".Low").css('background-color', 'red');
in browser console then also this works perfectly fine. can somebody tell me why this happens ?
$(".Low")
might not exist at the time your jQuery code executes. When you setTimeout
it allows $(".Low")
to be available then your jquery works.
You can check $(".Low").length
outside & inside the setTimeout
to findout if it exists in both cases or not.