Book Image

KnockoutJS Web Development

Book Image

KnockoutJS Web Development

Overview of this book

Table of Contents (13 chapters)
KnockoutJS Web Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Event binding


Let me start off by saying that I have not tested every type of event that can be bound to Knockout, but there are tons of events in HTML, or rather DOM, that can be tested. It seems with HTML5-friendly browsers the number of the browsers available to us has increased. I would suggest that you make sure that you test to validate if any newer events are actually available on the platform you are targeting.

When we bind an event it requires a handler. These handlers are either functions or methods on objects. The functions can be part of the ViewModel or external to the scope of the ViewModel. As a reminder, when functions are part of the ViewModel we can assign the function method without ( ). If we are passing arguments then we would, of course, use them, even if they were part of the ViewModel.

Common events we would look for in the View would include click, keypress, mouseover, and mouseout. There are many other events, but that is enough of a list to give you an idea of what...