Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you need to place a knockout.js binding handler in jQuery's document.ready

Do you need to place Knockout.js custom binding handlers (not knockout itself but binding handlers) in a jQuery's document.ready or is it safe to assume they will only fire the init and update functions after the DOM has loaded (Knockout will do it for you)?

like image 758
Phil Avatar asked Dec 06 '25 11:12

Phil


1 Answers

Custom binding handlers should be registered after Knockout has been loaded, but before ko.applyBindings is called, as it is when ko.applyBindings is called that the init and update functions of the bindings are called by Knockout (if there is an element in the DOM that is using that particular binding).

The call to ko.applyBindings should only happen when the DOM is ready, as explained here.

like image 77
Ric Avatar answered Dec 09 '25 00:12

Ric



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!