Skip to content

Instantly share code, notes, and snippets.

@GraemeF
Forked from garyshort/BrokenKnockout.html
Created December 21, 2011 18:45
Show Gist options
  • Save GraemeF/1507159 to your computer and use it in GitHub Desktop.
Save GraemeF/1507159 to your computer and use it in GitHub Desktop.
Broken Knockout
<html>
<body>
<form data-bind="submit: onSubmit">
<button type="submit">Submit</button>
</form>
<script type="text/javascript" src="knockout-2.0.0.js"></script>
<script type="text/javascript">
window.onload = function () {
var viewModel = {
onSubmit : function(formElement) {
alert('works');
}
};
ko.applyBindings(viewModel);
};
</script>
</body>
</html>
@GraemeF
Copy link
Author

GraemeF commented Dec 21, 2011

It wasn't loading the knockout library due to language attribute (I changed it to type, but it works if you remove it altogether too shrug), and it was trying to apply bindings to the DOM before the DOM was loaded (you could put that bit in your JQuery startup bit instead if you're also using that).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment