I\'m working with knockout.js to build dynamic lists and I\'m trying to figure out how I can get the DOM object associated with an object in my observable array. Specifical
The $(event.target) solution is good if it is related to an already occurring event in which the item's DOM element is at target. But sometimes you don't have the targeted item because there is no event (for example - you want to scroll a list to an item that was not gestured by the user).
In such case you can give the item's DOM element id attribute a unique value that contains the item id:
-
and then getDomObject() looks like:
getDomObject = function(item) { return $("#item_" + item.id); }