Give a bit of context of how your CMS binds the template (the JS file)
If your CMS uses template
binding then you can just use afterRender
.
Just like this:
var viewModel = function() {
this.myFunction = function() {
console.log("test");
}
}
ko.applyBindings(new viewModel());
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
<div data-bind="template: { name: 'tmpl-foo', afterRender: myFunction }"></div>
<script type="text/html" id="tmpl-foo">
<div id="myCMSdiv">
<p>My Content</p>
</div>
</script>
More info on template
binding here.
If your CMS uses it as a component
though then you need another approach.
Check this post on how to do it but the gist is just the same as above.