I did declare click like that in my template
<script id="flipTemplate" type="text/html">
<div data-bind="attr: {id: ImageName }, click: alert('a')">
......
</script>
But alert('a') executing straight away i clicking my button which is generated dynamic content instead of alerting when i am clicking on that div.
is there any way how to fix that?
knockoutjs expects a function as the click binding parameter not an arbitrary js statement.
So you need to wrap your alert call into an anonymous function
But I highly recommend to put every logic into your ko viewmodels and use the viewmodel methods in your bindings. So don’t put logic into the
data-bindexpressions.