Getting binding context on event in knockout

Damir Dobric Posts

Next talks:



Follow me on Twitter: #ddobric




This post is just for documentation purposes. We have often a requirement to obtain the binding context instance of the DOM element.
This is usually the case when you for example subscribe some event. Following sample shows a keyup event as a INPUT element which is a child of some DIV element.
The parent DIV of clicked INPUT element holds the binding context.

$("input[data-iscontentchange='true']").keyup(function (e){
   var clickedParentElement = $([0];


The ko.contextFor(clickedParentElement).$data holds the instance of the object which is bound to parent element.

Posted Mar 06 2014, 11:25 AM by Damir Dobric
Filed under: , is a .Net Community Blog powered by daenet GmbH.