I’m using the knockout external templating engine to create a section of my webpage. The template has a ul inside of it that I would like to perform a function on.
<ul id="myTags"></ul
So, for instance, once the template has been loaded from the server, I would like to call some method:
$("#myTags").doSomething(...)
How do I call this method once the template has been downloaded from the server, and inserted into the document? NOTE This may happen more than once….
The
templatebinding does have anafterRendercallback that you could use to process the new elements: http://knockoutjs.com/documentation/template-binding.html#note_3_using_afterrender_afteradd_and_beforeremoveI don’t know what you want to do with your element, but I would consider using a custom binding for this purpose. Custom bindings are described: http://knockoutjs.com/documentation/custom-bindings.html and http://www.knockmeout.net/2011/07/another-look-at-custom-bindings-for.html
Even if you just use the
initfunction of your custom binding, it will run every time that your template is rendered.