Binding image onerror event

1,138 views
Skip to first unread message

yuvalr80

unread,
Oct 11, 2012, 3:43:23 PM10/11/12
to knock...@googlegroups.com
I'd like to handle onerror events on images (mainly because of broken links) using event binding to my model.
Binding "event: {onerror: myHandler}" doesn't work (according to KO documentation event binding is only for form inputs).
Also binding it through "attr: {onerror: myHandler}" just binds the function as text into the attribute.

Is it possible to do?

Thanks
Yuval

rpn

unread,
Oct 11, 2012, 4:21:50 PM10/11/12
to knock...@googlegroups.com
Hi Yuval-
You need to drop the "on" in the event name, so it would look like: 

<img data-bind="event: { error: log }, attr: { src: 'blah.jpg' }" />

You would need to apply the src in a binding, as the event would not be attached until after ko.applyBindings is called.

Hope that helps.

yuvalr80

unread,
Oct 11, 2012, 5:19:50 PM10/11/12
to knock...@googlegroups.com
Thanks.
Reply all
Reply to author
Forward
0 new messages