Toggle get not working

I am using code from toggle example,

label class=“toggle toggle-init color-red”>
input type=“checkbox” checked>
span class=“toggle-icon”>
/label>

but this
app.toggle.get(’.toggle’);
return undefined.

Thanks

If it returns undefined then you call it when toggle element is not in DOM. Make sure you are calling it when it is presented in DOM

I put it in PageInit. What is correct place?
Thanks.

After being stuck on this for a while I realized you have to create it in pageInit.

var toggle = app.toggle.create({
el: ‘.toggle’
on: {
change: function () {
console.log(‘Toggle changed’)
}
}
})

then you can do toggle.toggle() ect.

I could not get toggle.get() to work