It looks like the element
you're referring to in
$(element).offset().top
is not actually a DOM object, it's a Knockout object. It contains some other data besides the HTML. The following yields the correct result, because it's referring to the DOM object:
this.render = function(element, data) {
if (data.name == "five") {
console.log( $('#five').offset().top );
}
}
I haven't used knockout before, so there may be a better way of accessing it, but I found that the object you're trying to access is actually in the element, it's just one level deep in the object, so that the following also works:
this.render = function(element, data) {
if (data.name == "five") {
console.log( $( element[1] ).offset().top );
}
}
(Note that I'm using console.log
for cleaner debugging. I prefer to not have all those alerts popping up.)