Reputation: 167
I am using Bootstrap in which I have an input checkbox like this:
<input type="checkbox" id="toggle" name="toggle">
And I'm using Bootstrap Switch to convert it into a switch using their function:
Meteor.startup(function() {
$("[name='toggle']").bootstrapSwitch();
});
However, the problem is that the switch only loads in half the time. I think this is because the function is being called before the checkbox is loaded in the DOM. I thought putting this into the Meteor startup function would fix it but it doesn't. How can I ensure this switch is loaded after the checkbox is loaded?
I've tried Template.body.onRendered
and it didn't work either.
Upvotes: 0
Views: 138
Reputation: 194
Consider, the above mention code is in template myTemplate
my_template.html
<template name="myTemplate">
<input type="checkbox" id="toggle" name="toggle"/>
</template>
then your my_template.js
will have
my_template.js
if(Meteor.isClient) {
Template.myTemplate.onRendered(function() {
$("[name='toggle']").bootstrapSwitch();
});
}
Upvotes: 1