Your code works fine with a
var input = $('<div>Append</div>');
However if you have multiple elements in your input, like
var input=$('<div>Line 1</div><div>Line 2</div>');
Both element are counted, so your length will return 2 if you have added it only once. Have all elements in one single <div>
and it wil work
var input=$('<div><div>Line 1</div><div>Line 2</div><div>');